#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int dx[] = {-1, 1, 0, 0}, dy[] = {0, 0, 1, -1};
const int MAX_N = 27;
int H, W;
string g[MAX_N];
int dist[MAX_N][MAX_N][MAX_N][MAX_N];
void solve() {
  memset(dist, 0x3f, sizeof(dist));
  int ans = 0;
  for (int i = 0; i < H; ++i)
    for (int j = 0; j < W; ++j)
      if (g[i][j] == '.') {
        for (int k = 0; k < 4; ++k) {
          int nx = i + dx[k], ny = j + dy[k];
          if (nx >= 0 && nx < H && ny >= 0 && ny < W && g[nx][ny] == '.')
            dist[i][j][nx][ny] = 1;
        }
      }
  for (int kx = 0; kx < H; ++kx)
    for (int ky = 0; ky < W; ++ky)
      for (int x = 0; x < H; ++x)
        for (int y = 0; y < W; ++y)
          if (g[x][y] == '.')
            for (int a = 0; a < H; ++a)
              for (int b = 0; b < W; ++b)
                if (g[a][b] == '.') {
                  dist[x][y][a][b] =
                      min(dist[x][y][a][b],
                          dist[x][y][kx][ky] + dist[kx][ky][a][b]);
                }
  for (int x = 0; x < H; ++x)
    for (int y = 0; y < W; ++y)
      if (g[x][y] == '.')
        for (int a = 0; a < H; ++a)
          for (int b = 0; b < W; ++b)
            if (g[a][b] == '.') {
              ans = max(ans, dist[x][y][a][b]);
            }
  cout << ans << '\n';
}
int main() {
  cin >> H >> W;
  for (int i = 0; i < H; ++i) cin >> g[i];
  solve();
  return 0;
}
