#include <bits/stdc++.h>
using namespace std;
int main() {
  const int dy[4] = {1, 0, -1, 0};
  const int dx[4] = {0, 1, 0, -1};
  int H, W;
  cin >> H >> W;
  vector<string> field(H);
  for (int i = 0; i < (H); ++i) cin >> field[i];
  vector<vector<int>> dist(H, vector<int>(W, -1));
  queue<pair<int, int>> que;
  int ans = -1;
  for (int sy = 0; sy < (H); ++sy) {
    for (int sx = 0; sx < (W); ++sx) {
      dist[sy][sx] = 0;
      que.push(make_pair(sy, sx));
      while (!que.empty()) {
        pair<int, int> v = que.front();
        que.pop();
        for (int i = 0; i < (4); ++i) {
          pair<int, int> nv(v.first + dy[i], v.second + dx[i]);
          if (nv.first < 0 || nv.first >= H || nv.second < 0 || nv.second >= W)
            continue;
          if (dist[nv.first][nv.second] != -1) continue;
          if (field[nv.first][nv.second] == '#') continue;
          dist[nv.first][nv.second] = dist[v.first][v.second] + 1;
          que.push(nv);
        }
      }
      int maxi = 0;
      for (int i = 0; i < (H); ++i)
        maxi = max(maxi, (int)*max_element(dist[i].begin(), dist[i].end()));
      ans = max(ans, maxi);
      dist.assign(H, vector<int>(W, -1));
    }
  }
  cout << ans;
}
