#include <bits/stdc++.h>
using namespace std;
const int INF = 10000;
int d[20][20];
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
char maze[20][20];
int h, w, hw, hwc;
int l = 0, mnx = 0, mny = 0;
bool flg = true;
int bfs(int sx, int sy) {
  int hwc = 0;
  queue<pair<int, int> > que;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) d[i][j] = INF;
  que.push(pair<int, int>(sx, sy));
  d[sx][sy] = 0;
  while (hw > hwc) {
    pair<int, int> p = que.front();
    que.pop();
    for (int i = 0; i < 4; i++) {
      int nx = p.first + dx[i], ny = p.second + dy[i];
      if (0 <= nx && nx < h && 0 <= ny && ny < w && maze[nx][ny] != '#' &&
          d[nx][ny] == INF) {
        que.push(pair<int, int>(nx, ny));
        d[nx][ny] = d[p.first][p.second] + 1;
        if (l < d[nx][ny]) {
          mnx = nx;
          mny = ny;
          l = d[nx][ny];
        }
      }
    }
    hwc++;
  }
  if (flg) {
    flg = false;
    return bfs(mnx, mny);
  }
  return l;
}
int main() {
  string s;
  cin >> h >> w;
  int sx = -1, sy = -1;
  for (int i = 0; i < h; i++) {
    cin >> s;
    for (int j = 0; j < w; j++) {
      if (sx == -1 && s[j] == '.') {
        sx = i;
        sy = j;
      }
      maze[i][j] = s[j];
    }
  }
  hw = h * w;
  cout << bfs(sx, sy);
  return 0;
}
