#include <bits/stdc++.h>
const int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};
char mp[50][50];
bool vis[50][50];
int ans;
struct Queue {
  int x, y, d;
} q[50 * 50];
int n, m;
void bfs(int x, int y) {
  memset(vis, 0, sizeof(vis));
  int head = 0, tail = 1;
  q[1] = (Queue){x, y, 0};
  vis[x][y] = 1;
  while (head < tail) {
    Queue now = q[++head];
    ans < now.d ? ans = now.d : 0;
    for (int i = 0; i < 4; ++i) {
      int nx = now.x + dx[i], ny = now.y + dy[i];
      if (!vis[nx][ny] && nx && ny && nx <= n && ny <= m && mp[nx][ny] != '#') {
        vis[nx][ny] = 1;
        q[++tail] = (Queue){nx, ny, now.d + 1};
      }
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%s", mp[i] + 1);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) bfs(i, j);
  printf("%d\n", ans);
  return 0;
}
