#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int INF = 1001001001;
int MAX_V = 21;
vector<vector<int>> d(MAX_V* MAX_V, vector<int>(MAX_V* MAX_V, INF));
void warshall_floyd() {
  for (int k = 0; k < MAX_V; ++k)
    for (int i = 0; i < MAX_V; ++i)
      for (int j = 0; j < MAX_V; ++j) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (long long(i) = 0; (i) < (h); (i)++) {
    cin >> s[i];
  }
  for (long long(i) = 0; (i) < (h * w); (i)++) d[i][i] = 0;
  for (long long(i) = 0; (i) < (h); (i)++)
    for (long long(j) = 0; (j) < (w); (j)++) {
      int dx[] = {1, -1, 0, 0};
      int dy[] = {0, 0, 1, -1};
      if (s[i][j] == '#') continue;
      for (long long(k) = 0; (k) < (4); (k)++) {
        int nx = dx[k] + i;
        int ny = dy[k] + j;
        if (0 <= nx && nx < h && 0 <= ny && ny < w && s[nx][ny] == '.') {
          d[nx * w + ny][i * w + j] = 1;
          d[i * w + j][nx * w + ny] = 1;
        }
      }
    }
  warshall_floyd();
  int ans = 0;
  for (long long(i) = 0; (i) < (h * w); (i)++)
    for (long long(j) = 0; (j) < (h * w); (j)++) {
      if (d[i][j] != INF) ans = max(ans, d[i][j]);
    }
  cout << ans << endl;
}
