#include <bits/stdc++.h>
using namespace std;
using pi = pair<int, int>;
int INF = 100000;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int h, w;
char mp[24][24];
vector<vector<int>> bfs(pi s) {
  queue<pi> que;
  vector<vector<int>> mc(24, vector<int>(24, INF));
  que.push(s);
  mc[s.first][s.second] = 0;
  while (!que.empty()) {
    pi pos = que.front();
    que.pop();
    int y = pos.first;
    int x = pos.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 && mp[ny][nx] != '#' &&
          mc[ny][nx] == INF) {
        mc[ny][nx] = mc[y][x] + 1;
        que.push({ny, nx});
      }
    }
  }
  return mc;
}
int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> mp[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      auto c = bfs(pi(i, j));
      for (int ii = 0; ii < h; ii++) {
        for (int jj = 0; jj < w; jj++) {
          if (c[ii][jj] == INF) continue;
          ans = max(ans, c[ii][jj]);
        }
      }
    }
  }
  cout << ans << endl;
}
