#include <bits/stdc++.h>
using namespace std;
int n, m;
int dis[25][25];
int mx[4] = {-1, 1, 0, 0};
int my[4] = {0, 0, 1, -1};
char map1[25][25];
void bs(int y, int x, int sy, int sx) {
  for (int i = 0; i < 4; i++) {
    int ny = y + my[i], nx = x + mx[i];
    if (sy == ny && sx == nx) continue;
    if (ny >= 0 && nx >= 0 && ny < n && nx < m) {
      if (map1[ny][nx] == '.') {
        if (dis[ny][nx] == 0 || (dis[ny][nx] > dis[y][x] + 1)) {
          dis[ny][nx] = dis[y][x] + 1;
          bs(ny, nx, sy, sx);
        }
      }
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> map1[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      dis[i][j] = 0;
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      bs(i, j, i, j);
      int maxnum = 0;
      for (int k = 0; k < n; k++) {
        for (int l = 0; l < m; l++) {
          if (dis[k][l] > maxnum) maxnum = dis[k][l];
          dis[k][l] = 0;
        }
      }
      if (ans < maxnum) ans = maxnum;
    }
  }
  cout << ans << endl;
}
