#include <bits/stdc++.h>
using ll = long long;
using namespace std;
constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;
int main(void) {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cin >> s[i][j];
    }
  }
  int dx[4] = {1, 0, -1, 0};
  int dy[4] = {0, 1, 0, -1};
  int ans = 0;
  for (int sx = 0; sx < h; ++sx) {
    for (int sy = 0; sy < w; ++sy) {
      if (s[sx][sy] == '#') continue;
      vector<vector<int> > dist(h, vector<int>(w, 1e9));
      queue<pair<int, int> > q;
      dist[sx][sy] = 0;
      q.push(make_pair(sx, sy));
      while (!q.empty()) {
        int nowx = q.front().first;
        int nowy = q.front().second;
        q.pop();
        for (int k = 0; k < 4; ++k) {
          int nx = nowx + dx[k];
          int ny = nowy + dy[k];
          if (nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
          if (s[nx][ny] == '#') continue;
          if (dist[nx][ny] > dist[nowx][nowy] + 1) {
            dist[nx][ny] = dist[nowx][nowy] + 1;
            q.push(make_pair(nx, ny));
          }
        }
      }
      int max_dist = 0;
      for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
          if (s[i][j] == '#') continue;
          max_dist = max(max_dist, dist[i][j]);
        }
      }
      ans = max(ans, max_dist);
    }
  }
  cout << ans << endl;
  return 0;
}
