#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w;
  cin >> h >> w;
  vector<string> a(h);
  for (auto&& e : a) {
    cin >> e;
  }
  int dy[] = {1, -1, 0, 0}, dx[] = {0, 0, 1, -1};
  int ans = 0;
  for (int sy = 0; sy < h; sy++) {
    for (int sx = 0; sx < w; sx++) {
      vector<vector<int>> c(h, vector<int>(w, -1));
      c[sy][sx] = 0;
      queue<pair<int, int>> q;
      q.push({sy, sx});
      while (!q.empty()) {
        auto p = q.front();
        q.pop();
        int y = p.first, x = p.second;
        for (int i = 0; i < 4; i++) {
          int ny = y + dy[i];
          int nx = x + dx[i];
          if (ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
          if (c[ny][nx] == -1 && a[ny][nx] == '.') {
            q.push({ny, nx});
            c[ny][nx] = c[y][x] + 1;
          }
        }
      }
      for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
          ans = max(ans, c[i][j]);
        }
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
