#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> a(h + 2, vector<char>(w + 2, 'e'));
  for (int i = 1; i <= h; i++)
    for (int j = 1; j <= w; j++) cin >> a[i][j];
  int ans = 0;
  for (int sy = 1; sy <= h; sy++) {
    for (int sx = 1; sx <= w; sx++) {
      vector<vector<int>> dist(h + 2, vector<int>(w + 2, -1));
      queue<pair<int, int>> que;
      dist[sy][sx] = 0;
      que.push({sy, sx});
      const int dy[4] = {1, 0, -1, 0};
      const int dx[4] = {0, 1, 0, -1};
      while (!que.empty()) {
        pair<int, int> p = que.front();
        que.pop();
        for (int i = 0; i < 4; i++) {
          int y_next = p.first + dy[i];
          int x_next = p.second + dx[i];
          if (dist[y_next][x_next] != -1) continue;
          if (a[y_next][x_next] == 'e' || a[y_next][x_next] == '#') continue;
          dist[y_next][x_next] = dist[p.first][p.second] + 1;
          que.push({y_next, x_next});
        }
      }
      int tmp_dist = 0;
      for (int i = 1; i <= h; i++)
        for (int j = 1; j <= w; j++) tmp_dist = max(tmp_dist, dist[i][j]);
      ans = max(ans, tmp_dist);
    }
  }
  cout << ans << endl;
  return 0;
}
