#include <bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> maze(H, vector<char>(W));
  for (int(h) = 0; (h) < (H); (h)++)
    for (int(w) = 0; (w) < (W); (w)++) cin >> maze[h][w];
  const int d[4] = {1, -1, 0, 0};
  int ans = 0;
  for (int(h) = 0; (h) < (H); (h)++)
    for (int(w) = 0; (w) < (W); (w)++) {
      vector<vector<int>> dist(H, vector<int>(W, 1e9));
      queue<pair<int, int>> que;
      dist[h][w] = 0;
      que.emplace(make_pair(h, w));
      while (!que.empty()) {
        int i, k;
        tie(i, k) = que.front();
        que.pop();
        for (int(j) = 0; (j) < (4); (j)++) {
          if (i + d[j] < 0 || i + d[j] >= H || k + d[j ^ 2] < 0 ||
              k + d[j ^ 2] >= W || dist[i + d[j]][k + d[j ^ 2]] != 1e9 ||
              maze[i + d[j]][k + d[j ^ 2]] == '#') {
            continue;
          }
          dist[i + d[j]][k + d[j ^ 2]] = dist[i][k] + 1;
          ans = max(ans, dist[i][k] + 1);
          que.emplace(make_pair(i + d[j], k + d[j ^ 2]));
        }
      }
    }
  cout << ans << endl;
}
