#include <bits/stdc++.h>
using namespace std;
int h, w;
string S[22];
bool vis[22][22];
int dis[22][22];
int x[] = {0, 1, -1, 0};
int y[] = {1, 0, 0, -1};
bool valid(int r, int c) { return (r >= 0 && r < h && c >= 0 && c < w); }
void bfs(int r, int c) {
  vis[r][c] = true;
  dis[r][c] = 0;
  queue<pair<int, int> > q;
  q.push({r, c});
  while (!q.empty()) {
    int ur = q.front().first;
    int uc = q.front().second;
    q.pop();
    for (int i = 0; i < 4; i++) {
      int vr = ur + x[i];
      int vc = uc + y[i];
      if (!valid(vr, vc)) continue;
      if (S[vr][vc] == '#') continue;
      if (vis[vr][vc]) continue;
      vis[vr][vc] = true;
      dis[vr][vc] = dis[ur][uc] + 1;
      q.push({vr, vc});
    }
  }
}
int get_max() {
  int mx = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (vis[i][j]) mx = max(mx, dis[i][j]);
    }
  }
  return mx;
}
void clean() {
  memset(vis, 0, sizeof vis);
  memset(dis, 0, sizeof dis);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    cin >> S[i];
  }
  for (int i = 0; i < h; i++) {
    bool stop = false;
    for (int j = 0; j < w; j++) {
      if (S[i][j] == '.') {
        bfs(i, j);
        stop = true;
        break;
      }
    }
    if (stop) break;
  }
  int mx = get_max();
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (vis[i][j] && dis[i][j] == mx) {
        clean();
        bfs(i, j);
        cout << get_max() << endl;
        return 0;
      }
    }
  }
}
