#include <bits/stdc++.h>
using namespace std;
int n, m;
long long sum;
int vis[25][25];
char ch[25][25];
const int fx[4] = {1, -1, 0, 0}, fy[4] = {0, 0, -1, 1};
queue<int> Qx, Qy;
int bfs(int x, int y) {
  memset(vis, 0, sizeof(vis));
  vis[x][y] = 1;
  Qx.push(x);
  Qy.push(y);
  int res = 1;
  while (!Qx.empty()) {
    int x = Qx.front(), y = Qy.front();
    Qx.pop();
    Qy.pop();
    for (int i = 0; i < 4; ++i) {
      int X = x + fx[i], Y = y + fy[i];
      if (X < 1 || X > n || Y < 1 || Y > m) continue;
      if (ch[X][Y] == '#') continue;
      if (!vis[X][Y]) {
        vis[X][Y] = vis[x][y] + 1;
        res = max(res, vis[X][Y]);
        Qx.push(X);
        Qy.push(Y);
      }
    }
  }
  return res - 1;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    scanf("%s", ch[i] + 1);
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) {
      ans = max(ans, bfs(i, j));
    }
  printf("%d", ans);
  return 0;
}
