#include <bits/stdc++.h>
using namespace std;
const int dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1};
const int INF = 1001001;
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> ma(h);
  for (int i = 0; i < h; i++) cin >> ma[i];
  int maxn = 0;
  for (int sx = 0; sx < h; sx++) {
    for (int sy = 0; sy < w; sy++) {
      if (ma[sx][sy] == '#') continue;
      queue<pair<int, int>> q;
      vector<vector<int>> ans(h, vector<int>(w, INF));
      q.push({sx, sy});
      ans[sx][sy] = 0;
      while (!q.empty()) {
        int x = q.front().first, y = q.front().second;
        q.pop();
        for (int i = 0; i < 4; i++) {
          int nx = x + dx[i], ny = y + dy[i];
          if (nx < 0 || nx >= h || ny < 0 || ny >= w || ans[nx][ny] != INF)
            continue;
          if (ma[nx][ny] == '#') continue;
          q.push({nx, ny});
          ans[nx][nx] = ans[x][y] + 1;
        }
      }
      for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
          if (ma[i][j] != '#') maxn = max(maxn, ans[i][j]);
        }
      }
    }
  }
  cout << maxn << endl;
  return 0;
}
