#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);
  }
  int ans = 0;
  for (int sy = 0; sy < h; sy++) {
    for (int sx = 0; sx < w; sx++) {
      for (int gy = 0; gy < h; gy++) {
        for (int gx = 0; gx < w; gx++) {
          if ((sx == gx && sy == gy) ||
              (s[sy][sx] == '#' || s[gy][gx] == '#')) {
            continue;
          }
          vector<vector<int>> dist(h, vector<int>(w, INF));
          queue<pair<int, int>> que;
          que.push({sx, sy});
          dist[sy][sx] = 0;
          vector<int> dx{1, -1, 0, 0};
          vector<int> dy{0, 0, 1, -1};
          while (!que.empty()) {
            int x = que.front().first;
            int y = que.front().second;
            que.pop();
            for (int i = 0; i < 4; i++) {
              int ix = x + dx[i];
              int iy = y + dy[i];
              if (ix < 0 || ix >= w || iy < 0 || iy >= h) continue;
              if (dist[iy][ix] < dist[y][x] + 1 || s[iy][ix] == '#') continue;
              dist[iy][ix] = dist[y][x] + 1;
              que.push({ix, iy});
            }
          }
          ans = max(ans, dist[gy][gx]);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
