#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = numeric_limits<long long>::max() / 2;
const long long dx[4] = {1, 0, -1, 0};
const long long dy[4] = {0, 1, 0, -1};
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  long long H, W, sx, sy;
  cin >> H >> W;
  char s[H][W];
  for (long long i = 0; i < H; ++i) {
    for (long long j = 0; j < W; ++j) {
      cin >> s[i][j];
    }
  }
  long long ans = 0;
  for (long long m = 0; m < H; m++) {
    for (long long n = 0; n < W; n++) {
      if (s[m][n] == '#') continue;
      sx = m;
      sy = n;
      long long dist[25][25];
      fill((long long*)dist, (long long*)(dist + W), INF);
      queue<pair<long long, long long> > que;
      dist[sx][sy] = 0;
      que.push(pair<long long, long long>(sx, sy));
      while (!que.empty()) {
        pair<long long, long long> p = que.front();
        que.pop();
        long long x = p.first;
        long long y = p.second;
        for (long long i = 0; i < 4; ++i) {
          long long nx = x + dx[i], ny = y + dy[i];
          if (nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
          if (s[nx][ny] == '#') continue;
          if (dist[nx][ny] > dist[x][y] + 1) {
            dist[nx][ny] = dist[x][y] + 1;
            que.push(pair<long long, long long>(nx, ny));
            ans = max(ans, dist[nx][ny]);
          }
        }
      }
    }
  }
  cout << ans << endl;
}
