#include <bits/stdc++.h>
using namespace std;
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;
        if (x - 1 >= 0 && s[x - 1][y] == '.' && !visited[x - 1][y]) {
          q.push(make_tuple(x - 1, y, d + 1));
          if (d + 1 > ans) ans = d + 1;
        }
        if (y - 1 >= 0 && s[x][y - 1] == '.' && !visited[x][y - 1]) {
          q.push(make_tuple(x, y - 1, d + 1));
          if (d + 1 > ans) ans = d + 1;
        }
        if (x + 1 < h && s[x + 1][y] == '.' && !visited[x + 1][y]) {
          q.push(make_tuple(x + 1, y, d + 1));
          if (d + 1 > ans) ans = d + 1;
        }
        if (y + 1 < w && s[x][y + 1] == '.' && !visited[x][y + 1]) {
          q.push(make_tuple(x, y + 1, d + 1));
          if (d + 1 > ans) ans = d + 1;
        }
      }
    }
  cout << ans << endl;
  return 0;
}
