#include <bits/stdc++.h>
using namespace std;
long long x[] = {1, 0, -1, 0}, y[] = {0, 1, 0, -1};
long long ans[25][25][25][25];
signed main(signed argc, char* argv[]) {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  long long 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; i++) {
    for (long long j = 0; j < w; j++) {
      queue<pair<pair<long long, long long>, long long>> que;
      que.push({{i, j}, 0});
      while (!que.empty()) {
        auto it = que.front();
        que.pop();
        long long px = it.first.first, py = it.first.second, point = it.second;
        if (ans[i][j][px][py] != 0) continue;
        if (s[px][py] == '#') {
          ans[i][j][px][py] = -1;
          continue;
        }
        ans[i][j][px][py] = point;
        for (long long k = 0; k < 4; k++) {
          if (0 <= px + x[k] && px + x[k] < h && 0 <= py + y[k] &&
              py + y[k] < w) {
            que.push({{px + x[k], py + y[k]}, point + 1});
          }
        }
      }
    }
  }
  long long an = 0;
  for (long long i = 0; i < h; i++) {
    for (long long j = 0; j < w; j++) {
      for (long long k = 0; k < h; k++) {
        for (long long l = 0; l < w; l++) {
          an = max(an, ans[i][j][k][l]);
        }
      }
    }
  }
  cout << an << endl;
}
