#include <bits/stdc++.h>
using namespace std;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, -1, 1};
int d[500][500];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int h, w;
  cin >> h >> w;
  int N = h * w;
  char s[h][w];
  for (int(i) = 0; (i) < (h); (i)++)
    for (int(j) = 0; (j) < (w); (j)++) cin >> s[i][j];
  for (int(i) = 0; (i) < (500); (i)++)
    for (int(j) = 0; (j) < (500); (j)++) d[i][j] = 1000;
  for (int(i) = 0; (i) < (h); (i)++)
    for (int(j) = 0; (j) < (w); (j)++) {
      if (s[i][j] == '#') continue;
      int num = i * w + j;
      for (int(k) = 0; (k) < (4); (k)++) {
        int nx = i + dx[k], ny = j + dy[k];
        if (nx < 0 || ny < 0 || nx >= h || ny >= w || s[nx][ny] == '#')
          continue;
        int num2 = nx * w + ny;
        d[num][num2] = 1;
        d[num2][num] = 1;
      }
    }
  for (int(i) = 0; (i) < (N); (i)++)
    for (int(j) = 0; (j) < (N); (j)++)
      for (int(k) = 0; (k) < (N); (k)++)
        if (d[j][i] + d[i][k] < d[j][k]) d[j][k] = d[j][i] + d[i][k];
  int ans = 0;
  for (int(i) = 0; (i) < (N); (i)++)
    for (int(j) = 0; (j) < (N); (j)++)
      if (d[i][j] < 1000)
        if (d[i][j] > ans) ans = d[i][j];
  cout << ans << endl;
  return 0;
}
