#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const long long INFL = 0x3f3f3f3f3f3f3f3f;
char s[30][30];
int dx[]{1, -1, 0, 0}, dy[]{0, 0, 1, -1};
int d[30][30];
int main() {
  int h, w;
  cin >> h >> w;
  for (int i = 0; i < (h); i++) scanf("%s", s[i]);
  int Max = 0;
  for (int sx = 0; sx < (h); sx++)
    for (int sy = 0; sy < (w); sy++) {
      memset(d, -1, sizeof(d));
      d[sx][sy] = 0;
      queue<pair<int, int> > que;
      que.push(pair<int, int>(sx, sy));
      while (!que.empty()) {
        pair<int, int> p = que.front();
        que.pop();
        for (int k = 0; k < (4); k++) {
          int nx = p.first + dx[k], ny = p.second + dy[k];
          if (0 <= nx && nx < h && 0 <= ny && ny < w && s[nx][ny] == '.' &&
              d[nx][ny] == -1) {
            d[nx][ny] = d[p.first][p.second] + 1;
            que.push(pair<int, int>(nx, ny));
          }
        }
      }
      for (int i = 0; i < (h); i++)
        for (int j = 0; j < (w); j++) {
          Max = max(Max, d[i][j]);
        }
    }
  cout << Max << endl;
}
