#include <bits/stdc++.h>
using namespace std;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, -1, 1};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int h, w;
  cin >> h >> w;
  char s[h][w];
  for (int(i) = 0; (i) < (h); (i)++)
    for (int(j) = 0; (j) < (w); (j)++) cin >> s[i][j];
  int ans = 0;
  bool visited[h][w];
  for (int(i) = 0; (i) < (h); (i)++)
    for (int(j) = 0; (j) < (w); (j)++) {
      if (s[i][j] == '#') continue;
      int tmp = 0;
      memset(visited, false, sizeof(visited));
      queue<tuple<int, int, int>> q;
      q.push(make_tuple(i, j, 0));
      visited[i][j] = true;
      while (!q.empty()) {
        auto p = q.front();
        q.pop();
        int x = get<0>(p), y = get<1>(p), d = get<2>(p);
        visited[x][y] = true;
        for (int(k) = 0; (k) < (4); (k)++) {
          int nx = x + dx[k], ny = y + dy[k];
          if (nx >= 0 && ny >= 0 && nx <= h - 1 && ny <= w - 1 &&
              !visited[nx][ny] && s[nx][ny] == '.') {
            q.push(make_tuple(nx, ny, d + 1));
            if (d + 1 > ans) ans = d + 1;
          }
        }
      }
    }
  cout << ans << endl;
  return 0;
}
