#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e2 + 5;
int dis[maxn][maxn];
char mp[maxn][maxn];
int num[maxn][maxn];
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
int main() {
  memset(dis, 0x3f, sizeof(dis));
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%s", mp[i] + 1);
  }
  int cnt = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (mp[i][j] == '.') num[i][j] = cnt++;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (mp[i][j] == '.') {
        for (int k = 0; k < 4; k++) {
          int xx = i + dx[k];
          int yy = j + dy[k];
          if (mp[xx][yy] == '.') {
            dis[num[i][j]][num[xx][yy]] = 1;
          }
        }
      }
    }
  }
  for (int k = 1; k < cnt; k++) {
    for (int i = 1; i < cnt; i++) {
      for (int j = 1; j < cnt; j++) {
        if (dis[i][j] > dis[i][k] + dis[k][j]) {
          dis[i][j] = dis[i][k] + dis[k][j];
        }
      }
    }
  }
  int ans = 0;
  for (int i = 1; i < cnt; i++) {
    for (int j = 1; j < cnt; j++) {
      ans = max(ans, dis[i][j]);
    }
  }
  printf("%d", ans);
  return 0;
}
