#include <bits/stdc++.h>
const int INF = 1001001001;
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
using namespace std;
int h, w;
char grid[25][25];
int memo[25][25];
int rec(int sx, int sy, int tx, int ty) {
  if (sx == tx && sy == ty) return 0;
  if (memo[sy][sx] >= 0) return memo[sy][sx];
  int ans = INF;
  for (int i = 0; i < (4); ++i) {
    int nsx = sx + dx[i];
    int nsy = sy + dy[i];
    if (0 <= nsx && nsx < w && 0 <= nsy && nsy < h && memo[nsy][nsx] < 0 &&
        grid[nsy][nsx] != '#')
      ans = min(rec(nsx, nsy, tx, ty) + 1, ans);
  }
  return memo[sy][sx] = ans;
}
int main() {
  cin >> h >> w;
  for (int i = 0; i < (h); ++i)
    for (int j = 0; j < (w); ++j) cin >> grid[i][j];
  int ans = 0;
  for (int sy = 0; sy < (h); ++sy)
    for (int sx = 0; sx < (w); ++sx)
      for (int ty = 0; ty < (h); ++ty)
        for (int tx = 0; tx < (w); ++tx) {
          if (grid[sy][sx] != '#' && grid[ty][tx] != '#') {
            memset(memo, -1, sizeof(memo));
            ans = max(rec(sx, sy, tx, ty), ans);
          }
        }
  cout << ans << endl;
  return 0;
}
