#include <bits/stdc++.h>
using namespace std;
const long long maxn = 21;
string s[maxn];
long long dist[maxn][maxn];
bool mark[maxn][maxn];
long long dx[4] = {1, -1, 0, 0}, dy[4] = {0, 0, 1, -1};
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, m, ans = 0;
  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] == '#') continue;
      for (long long k = 0; k < n; k++) {
        fill(dist[k], dist[k] + m, 0);
        fill(mark[k], mark[k] + m, 0);
      }
      queue<pair<long long, long long> > Q;
      Q.push(pair<long long, long long>(i, j));
      while (Q.size()) {
        auto P = Q.front();
        Q.pop();
        long long a = P.first, b = P.second;
        for (long long d = 0; d < 4; d++) {
          long long x = a + dx[d];
          long long y = b + dy[d];
          if (x >= 0 && x < n && y >= 0 && y < m && !mark[x][y] &&
              s[x][y] == '.') {
            Q.push(pair<long long, long long>(x, y));
            mark[x][y] = 1;
            dist[x][y] = dist[a][b] + 1;
          }
        }
      }
      for (long long k = 0; k < n; k++) {
        ans = max(ans, *max_element(dist[k], dist[k] + m));
      }
    }
  }
  cout << ans;
}
