#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> m(h + 5);
  for (int ii = 0; ii < h; ii++) {
    cin >> m[ii];
  }
  const int INF = 1001001001;
  int di[] = {-1, 0, 1, 0};
  int dj[] = {0, -1, 0, 1};
  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, INF));
      queue<pair<int, int> > q;
      auto update = [&](int i, int j, int x) {
        if (dist[i][j] != INF) return;
        dist[i][j] = x;
        q.push(pair<int, int>(i, j));
      };
      update(i, j, 0);
      if (m[i][j] == '#') continue;
      while (!q.empty()) {
        int i_now = q.front().first;
        int j_now = q.front().second;
        q.pop();
        for (int d = 0; d < 4; d++) {
          int ni = i_now + di[d], nj = j_now + dj[d];
          if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
          if (m[ni][nj] == '#') continue;
          update(ni, nj, dist[i_now][j_now] + 1);
        }
      }
      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;
}
