#include <bits/stdc++.h>
using namespace std;
vector<long long int> adj[405];
long long int vis[405] = {0};
long long int bfs(long long int a) {
  long long int i, p, r;
  queue<long long int> q;
  q.push(a);
  vis[a] = 1;
  while ((long long int)q.size()) {
    p = q.front();
    for (i = 0; i < (long long int)adj[p].size(); i++) {
      if (!vis[adj[p][i]]) {
        vis[adj[p][i]] = 1;
        q.push(adj[p][i]);
      }
    }
    q.pop();
  }
  for (i = 0; i < 405; i++) vis[i] = 0;
  q.push(p);
  long long int d[405] = {0}, ma = 0;
  vis[p] = 1;
  d[p] = 0;
  while ((long long int)q.size()) {
    r = q.front();
    for (i = 0; i < (long long int)adj[r].size(); i++) {
      if (!vis[adj[r][i]]) {
        vis[adj[r][i]] = 1;
        q.push(adj[r][i]);
        d[adj[r][i]] = d[r] + 1;
        ma = max(ma, d[adj[r][i]]);
      }
    }
    q.pop();
  }
  return ma;
}
void shikhar7s(long long int cas) {
  long long int n, m, i, j;
  cin >> n >> m;
  char c[n][m];
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) cin >> c[i][j];
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (c[i][j] != '#') {
        if (i > 0 && c[i - 1][j] == '.') {
          adj[(m * i) + j].push_back((m * (i - 1)) + j);
        }
        if (j > 0 && c[i][j - 1] == '.') {
          adj[(m * i) + j].push_back((m * i) + j - 1);
        }
        if (i < n - 1 && c[i + 1][j] == '.') {
          adj[(m * i) + j].push_back((m * (i + 1)) + j);
        }
        if (j < m - 1 && c[i][j + 1] == '.') {
          adj[(m * i) + j].push_back((m * i) + j + 1);
        }
      }
    }
  }
  cout << bfs(1);
}
signed main() {
  std::ios_base::sync_with_stdio(false);
  long long int t = 1;
  long long int cas = 1;
  while (cas <= t) {
    shikhar7s(cas);
    cas++;
  }
  return 0;
}
