#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;
const long long INFL = 1e17;
const int MOD = 1e9 + 7;
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s;
  for (int i = 0; i < h; i++) {
    string t;
    cin >> t;
    s.push_back(t);
  }
  vector<int> dx{1, -1, 0, 0};
  vector<int> dy{0, 0, 1, -1};
  int ans = 0;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') continue;
      vector<vector<int>> dist(h, vector<int>(w, INF));
      queue<pair<int, int>> que;
      que.push({j, i});
      dist[i][j] = 0;
      while (!que.empty()) {
        int x = que.front().first;
        int y = que.front().second;
        que.pop();
        for (int dir = 0; dir < 4; dir++) {
          int ix = x + dx[i], iy = y + dy[i];
          if (ix < 0 || ix >= w || iy < 0 || iy >= h) continue;
          if (s[iy][ix] == '#') continue;
          if (dist[iy][ix] != INF) continue;
          dist[iy][ix] = dist[y][x] + 1;
          que.push({ix, iy});
        }
      }
      for (int ii = 0; ii < h; ii++)
        for (int jj = 0; jj < w; jj++) {
          if (dist[ii][jj] != INF) {
            ans = max(ans, dist[ii][jj]);
          }
        }
    }
  cout << ans << endl;
  return 0;
}
