#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long inf = 1ll << 61;
struct edge {
  long long to, cost;
};
string s[25];
long long dis[22][22];
long long dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
void init() {
  for (long long i = 0; i < 22; i++)
    for (long long j = 0; j < 22; j++) dis[i][j] = 0;
}
signed main() {
  long long h, w;
  cin >> h >> w;
  for (long long i = 0; i < h; i++) cin >> s[i];
  long long ans = 0;
  for (long long i = 0; i < h; i++) {
    for (long long j = 0; j < w; j++) {
      if (s[i][j] == '.') {
        init();
        queue<pair<long long, long long> > Q;
        Q.push(pair<long long, long long>(0, i * w + j));
        while (Q.size()) {
          pair<long long, long long> p = Q.front();
          Q.pop();
          long long X = p.second / w, Y = p.second % w;
          for (long long k = 0; k < 4; k++) {
            long long nx = X + dx[k], ny = Y + dy[k];
            if (0 <= nx && nx < h && 0 <= ny && ny < w && s[nx][ny] == '.' &&
                !dis[nx][ny]) {
              dis[nx][ny] = dis[X][Y] + 1;
              Q.push(pair<long long, long long>(dis[nx][ny], nx * w + ny));
            }
          }
        }
        long long res = 0;
        for (long long i = 0; i < h; i++)
          for (long long j = 0; j < w; j++) res = max(res, dis[i][j]);
        ans = max(ans, res);
      }
    }
  }
  cout << ans << endl;
}
