#include <bits/stdc++.h>
using namespace std;
int n, m;
char map[22][22];
int d[22][22];
int bfs(int sx, int sy) {
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) d[i][j] = -1;
  queue<pair<int, int> > q;
  q.push({sx, sy});
  d[sx][sy] = 0;
  int r = 0;
  while (!q.empty()) {
    int x = q.front().first, y = q.front().second;
    r = d[x][y];
    int dx[4] = {0, 1, 0, -1};
    int dy[4] = {1, 0, -1, 0};
    for (int k = 0; k < 4; k++) {
      int px = x + dx[k], py = y + dy[k];
      if (px < 0 || px >= n || py < 0 || py >= m || map[px][py] == '#')
        continue;
      if (d[px][py] == -1) {
        q.push({px, py});
        d[px][py] = d[x][y] + 1;
      }
    }
  }
  return r;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", map[i]);
  int ans = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (map[i][j] == '.') {
        int a = bfs(i, j);
        if (ans < a) ans = a;
      }
  printf("%d\n", ans);
  return 0;
}
