#include <bits/stdc++.h>
using namespace std;
char mp[21][21];
int fx[10001], fy[10001], f[21][21][21][21], t[21][21][21][21];
int xmo[4] = {1, -1, 0, 0}, ymo[4] = {0, 0, 1, -1};
int ans;
int main() {
  int h, w;
  scanf("%d%d", &h, &w);
  for (int i = 0; i < h; i++) scanf("%s", mp[i]);
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) {
      if (mp[i][j] != '#') {
        int l = 1, r = 2;
        fx[l] = i, fy[l] = j;
        while (l < r) {
          for (int k = 0; k < 4; k++) {
            int xx = fx[l] + xmo[k], yy = fy[l] + ymo[k];
            if (xx >= 0 && yy >= 0 && xx < h && yy < w) {
              if (mp[xx][yy] != '#' && !t[i][j][xx][yy]) {
                t[i][j][xx][yy] = 1;
                fx[r] = xx;
                fy[r] = yy;
                f[i][j][xx][yy] = f[i][j][fx[l]][fy[l]] + 1;
                ans = max(f[i][j][xx][yy], ans);
                r++;
              }
            }
          }
          l++;
        }
      }
    }
  printf("%d", ans);
  return 0;
}
