#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};
const int inf = 1000000;
int R, C;
int sx, sy, gx, gy;
char c[22][22];
int d[22][22];
int bfs() {
  queue<pair<int, int> > que;
  for (int y = 0; y < R; y++)
    for (int x = 0; x < C; x++) d[x][y] = inf;
  que.push(pair<int, int>(sx, sy));
  d[sx][sy] = 0;
  while (que.size()) {
    pair<int, int> p = que.front();
    que.pop();
    if (p.first == gx && p.second == gy) break;
    for (int i = 0; i < 4; ++i) {
      int nx = p.first + dx[i], ny = p.second + dy[i];
      if (0 <= nx && nx < C && 0 <= ny && ny < R && c[nx][ny] != '#' &&
          d[nx][ny] == inf) {
        que.push(pair<int, int>(nx, ny));
        d[nx][ny] = d[p.first][p.second] + 1;
      }
    }
  }
  return d[gx][gy];
}
int main() {
  cin >> R >> C;
  for (int y = 0; y < R; y++) {
    for (int x = 0; x < C; x++) {
      cin >> c[x][y];
    }
  }
  int ans = 0;
  for (sx = 0; sx < C; sx++) {
    for (sy = 0; sy < R; sy++) {
      for (gx = 0; gx < C; gx++) {
        for (gy = 0; gy < R; gy++) {
          if ((c[sx][sy] == '#' || c[gx][gy] == '#')) {
            break;
          }
          int res = bfs();
          if (d[gx][gy] == inf) {
            break;
          }
          ans = max(ans, res);
        }
      }
    }
  }
  cout << ans << endl;
}
