#include <cstdio>
#include <cstring>

#define maxn 50
char mp[maxn][maxn];
bool vis[maxn][maxn];
int ans;
struct Queue {
  int x, y, d;
} q[maxn * maxn];
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])
      {
        vis[nx][ny] = 1;
        q[++tail] = (Queue) {nx, ny, now.d + 1};
      }
    }
  }
}
int main()
{
  int n, m; 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;
}