#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 7;
long long dx[4] = {1, -1, 0, 0}, dy[4] = {0, 0, 1, -1};
long long a[500][500], d[500][500];
long long n, m;
string s[22];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  for (long long i = 0; i < n; i++) {
    cin >> s[i];
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (s[i][j] == '.') {
        for (long long k = 0; k < 4; k++)
          if (i + dx[k] < n && i + dx[k] >= 0 && j + dy[k] < m &&
              j + dy[k] >= 0) {
            if (s[i + dx[k]][j + dy[k]] == '.') {
              d[i * m + j][(i + dx[k]) * m + j + dy[k]] = 1;
              d[(i + dx[k]) * m + j + dy[k]][i * m + j] = 1;
            }
          }
      }
    }
  }
  for (long long i = 0; i < n * m; i++) {
    for (long long j = 0; j < n * m; j++)
      if (!d[i][j]) d[i][j] = INF;
  }
  long long ans = 0;
  for (long long k = 0; k < n * m; k++) {
    for (long long i = 0; i < n * m; i++) {
      for (long long j = 0; j < n * m; j++)
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
    }
  }
  for (long long i = 0; i < n * m; i++) {
    for (long long j = 0; j < n * m; j++) {
      if (d[i][j] < INF) ans = max(ans, d[i][j]);
    }
  }
  cout << ans;
}
