#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = (int)1e9 + 7;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int main() {
  int h, w;
  scanf("%d%d", &h, &w);
  char grid[h + 1][w + 1];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      scanf(" %c", &grid[i][j]);
    }
  }
  int ans = 0;
  for (int row = 0; row < h; row++) {
    for (int col = 0; col < w; col++) {
      int dist[h + 1][w + 1];
      int vis[h + 1][w + 1];
      memset(dist, 0, sizeof(dist));
      memset(vis, 0, sizeof(vis));
      queue<pair<int, int>> q;
      q.push({row, col});
      while (!q.empty()) {
        int x, y;
        tie(x, y) = q.front();
        q.pop();
        vis[x][y] = 1;
        if (grid[x][y] == '#') continue;
        for (int i = 0; i < 4; i++) {
          int tx = x + dx[i];
          int ty = y + dy[i];
          if (tx >= h || tx < 0 || ty >= w || ty < 0) continue;
          if (grid[tx][ty] == '.' && !vis[tx][ty]) {
            if (dist[tx][ty] == 0) {
              dist[tx][ty] = dist[x][y] + 1;
              ans = max(ans, dist[tx][ty]);
            }
            q.push({tx, ty});
          }
        }
      }
    }
  }
  printf("%d\n", ans);
}
