#include <bits/stdc++.h>
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD = int(1e9) + 7;
using namespace std;
using pii = pair<int, int>;
const int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
int h, w, dist[25][25];
char c[25][25];
queue<pair<int, int>> que;
void BFS() {
  int y, x;
  while (!que.empty()) {
    tie(y, x) = que.front();
    que.pop();
    for (int i = 0; i < (4); i++) {
      int ny = y + dy[i];
      int nx = x + dx[i];
      if (c[ny][nx] != '#' && dist[ny][nx] > dist[y][x] + 1 &&
          (ny <= h && 1 <= ny && nx <= w && 1 <= nx)) {
        dist[ny][nx] = dist[y][x] + 1;
        que.emplace(ny, nx);
      }
    }
  }
  return;
}
signed main(void) {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cin >> h >> w;
  for (int i = 1; i <= (h); i++) {
    for (int j = 1; j <= (w); j++) {
      cin >> c[i][j];
    }
  }
  int ans = 0;
  for (int i = 1; i <= (h); i++) {
    for (int j = 1; j <= (w); j++) {
      if (c[i][j] == '.') {
        memset(dist, INF, sizeof(dist));
        que.emplace(j, i);
        dist[j][i] = 0;
        BFS();
        for (int na = 1; na <= (h); na++) {
          for (int su = 1; su <= (w); su++) {
            if (dist[na][su] != INF) ans = max(ans, dist[na][su]);
          }
        }
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
