#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops")
using namespace std;
int g[20][20];
void init() {
  for (int i = 0; i < 20; ++i)
    for (int j = 0; j < 20; ++j) g[i][j] = (1000000000);
}
void WarshallFloyd() {
  for (int k = 0; k < 20; k++) {
    for (int i = 0; i < 20; i++) {
      for (int j = 0; j < 20; j++) {
        if (g[i][k] == (1000000000) || g[k][j] == (1000000000)) continue;
        g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
      }
    }
  }
}
signed main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < h; ++i) cin >> s[i];
  init();
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (s[i][j] == '#') continue;
      int now = w * i + j;
      if (i > 0 && s[i - 1][j] != '#') {
        int up = now - w;
        g[now][up] = 1;
      }
      if (i < h - 1 && s[i + 1][j] != '#') {
        int down = now + w;
        g[now][down] = 1;
      }
      if (j < w - 1 && s[i][j + 1] != '#') {
        int right = now + 1;
        g[now][right] = 1;
      }
      if (j > 0 && s[i][j - 1] != '#') {
        int left = now - 1;
        g[now][left] = 1;
      }
    }
  }
  WarshallFloyd();
  int res = 0;
  for (int i = 0; i < 20; ++i)
    for (int j = 0; j < 20; ++j)
      if (g[i][j] < (1000000000)) res = max(res, g[i][j]);
  cout << res << endl;
  return 0;
}
