#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  char s[h][w];
  int H[] = {0, 1, 0, -1}, W[] = {1, 0, -1, 0};
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> s[i][j];
    }
  }
  for (int startx = 0; startx < h; startx++) {
    for (int starty = 0; starty < w; starty++) {
      int visit[h][w];
      for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
          visit[i][j] = -1;
        }
      }
      queue<pair<int, int>> que;
      visit[startx][starty] = 0;
      que.push(make_pair(startx, starty));
      while (!que.empty()) {
        pair<int, int> now = que.front();
        que.pop();
        int nx = now.first, ny = now.second;
        for (int k = 0; k < 4; k++) {
          if (nx + H[k] < 0 || nx + H[k] > h - 1 || ny + W[k] < 0 ||
              ny + W[k] > w - 1)
            continue;
          if (visit[nx + H[k]][ny + W[k]] != -1 ||
              s[nx + H[k]][ny + W[k]] == '#')
            continue;
          pair<int, int> next = make_pair(nx + H[k], ny + W[k]);
          que.push(next);
          visit[next.first][next.second] = visit[nx][ny] + 1;
          ans = max(ans, visit[next.first][next.second]);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
