#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int h, w;
char grid[25][25];
int dis[25][25];
int INF = INT_MAX;
void dfs(int i, int j, int pre = 0) {
  if (i < 0 || i >= h || j < 0 || j >= w) return;
  if (grid[i][j] == '#') return;
  if (dis[i][j] < pre) return;
  dis[i][j] = pre;
  dfs(i + 1, j, pre + 1);
  dfs(i - 1, j, pre + 1);
  dfs(i, j + 1, pre + 1);
  dfs(i, j - 1, pre + 1);
}
int main() {
  cin >> h >> w;
  for (int i = 0; i < (int)(h); i++)
    for (int j = 0; j < (int)(w); j++) {
      cin >> grid[i][j];
    }
  int ans = 0;
  for (int i = 0; i < (int)(h); i++)
    for (int j = 0; j < (int)(w); j++) {
      if (grid[i][j] == '#') continue;
      for (int p = 0; p < (int)(h); p++)
        for (int q = 0; q < (int)(w); q++) {
          dis[p][q] = INF;
        }
      dfs(i, j);
      int now = 0;
      for (int p = 0; p < (int)(h); p++)
        for (int q = 0; q < (int)(w); q++) {
          if (grid[p][q] != '#') now = max(now, dis[p][q]);
        }
      ans = max(now, ans);
    }
  cout << ans << endl;
}
