#include <bits/stdc++.h>
using namespace std;
inline int gi() {
  int f = 1, sum = 0;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    sum = (sum << 3) + (sum << 1) + ch - '0';
    ch = getchar();
  }
  return f * sum;
}
const int N = 42;
int h, w, ans, d[N][N], vis[N][N];
char a[N][N];
queue<int> qx, qy;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
void bfs(int x, int y) {
  memset(d, 0, sizeof(d));
  memset(vis, 0, sizeof(vis));
  qx.push(x);
  qy.push(y);
  vis[x][y] = 1;
  while (!qx.empty()) {
    int nx = qx.front(), ny = qy.front();
    qx.pop();
    qy.pop();
    for (int i = 0; i < 4; i++) {
      int xx = nx + dx[i], yy = ny + dy[i];
      if (xx < 1 || yy < 1 || xx > h || yy > w || vis[xx][yy] ||
          a[xx][yy] == '#')
        continue;
      d[xx][yy] = d[nx][ny] + 1;
      qx.push(xx);
      qy.push(yy);
      vis[xx][yy] = 1;
      ans = max(ans, d[xx][yy]);
    }
  }
}
int main() {
  h = gi();
  w = gi();
  for (int i = 1; i <= h; i++) scanf("%s", a[i] + 1);
  for (int i = 1; i <= h; i++)
    for (int j = 1; j <= w; j++)
      if (a[i][j]) bfs(i, j);
  printf("%d\n", ans);
  return 0;
}
