#include <bits/stdc++.h>
const int INF = 100010000;
using namespace std;
int h, w;
int ans = 0;
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
int main() {
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < h; i++) cin >> s[i];
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) {
      queue<std::pair<int, int>> q;
      vector<vector<int>> dist(h, vector<int>(w, INF));
      auto update = [&](int x, int y, int z) {
        if (dist[x][y] != INF) return;
        dist[x][y] = z;
        q.push(std::pair<int, int>(x, y));
      };
      update(i, j, 0);
      while (!q.empty()) {
        int ci = q.front().first;
        int cj = q.front().second;
        q.pop();
        for (int dis = 0; dis < 4; dis++) {
          int ni = ci + di[dis];
          int nj = cj + dj[dis];
          if (s[ni][nj] == '#') continue;
          if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
          update(ni, nj, dist[ci][cj] + 1);
        }
      }
      for (int a = 0; a < h; a++)
        for (int b = 0; b < w; b++) {
          if (dist[a][b] == INF) continue;
          ans = max(ans, dist[a][b]);
        }
    }
  cout << ans << endl;
}
