#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w;
  cin >> h >> w;
  vector<string> g(h);
  int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
  for (int i = 0; i < h; i++) cin >> g[i];
  int ans = 0;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) {
      vector<vector<int>> dist(h, vector<int>(w, -1));
      dist[i][j] = 0;
      queue<pair<int, int>> que;
      que.emplace(i, j);
      while (que.size()) {
        auto cur = que.front();
        que.pop();
        for (int k = 0; k < 4; k++) {
          int x = cur.first + dx[k];
          int y = cur.second + dy[k];
          if (x < 0 || x >= h || y < 0 || y >= w || g[x][y] == '#') continue;
          if (dist[x][y] == -1) {
            dist[x][y] = dist[cur.first][cur.second] + 1;
            que.emplace(x, y);
          }
        }
      }
      int d = 0;
      for (int ii = 0; ii < h; ii++)
        for (int jj = 0; jj < w; jj++) {
          d = max(dist[ii][jj], d);
        }
      ans = max(d, ans);
    }
  cout << ans << '\n';
  return 0;
}
