#include <bits/stdc++.h>
const int dx[4] = {0, -1, 1, 0};
const int dy[4] = {-1, 0, 0, 1};
const int INF = 1e9 + 7;
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  char s[20][20];
  for (int i = (0); i <= (h - 1); i++)
    for (int j = (0); j <= (w - 1); j++) cin >> s[i][j];
  int ans = 0;
  int d[20][20];
  for (int i = (0); i <= (h - 1); i++) {
    for (int j = (0); j <= (w - 1); j++) {
      queue<pair<int, int> > Q;
      for (int k = (0); k <= (21 - 1); k++)
        for (int l = (0); l <= (21 - 1); l++) d[k][l] = INF;
      if (s[i][j] == '#') continue;
      Q.push({i, j});
      d[i][j] = 0;
      while (!Q.empty()) {
        int y = Q.front().first;
        int x = Q.front().second;
        Q.pop();
        for (int k = 0; k < 4; k++) {
          int ny = y + dy[k];
          int nx = x + dx[k];
          if (0 <= ny && ny < h && 0 <= nx && nx < w && s[ny][nx] == '.' &&
              d[ny][nx] == INF) {
            Q.push({ny, nx});
            d[ny][nx] = d[y][x] + 1;
          }
        }
      }
      for (int k = (0); k <= (h - 1); k++) {
        for (int l = (0); l <= (w - 1); l++) {
          if (d[k][l] == INF) continue;
          ans = max(ans, d[k][l]);
        }
      }
    }
  }
  cout << ans << endl;
}
