#include <bits/stdc++.h>
using namespace std;
const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
int dist[20][20][20][20], n, m, ans;
string s[20];
void DFS(int r, int w, int rr, int ww, int ret) {
  dist[r][w][rr][ww] = ret;
  ret++;
  for (int i = 0; i < 4; i++) {
    int nr = rr + dx[i], nw = ww + dy[i];
    if (nr < 0 || nr >= n || nw < 0 || nw >= m || s[nr][nw] == '#' ||
        (ret > dist[r][w][nr][nw] && dist[r][w][nr][nw] >= 0)) {
      continue;
    }
    DFS(r, w, nr, nw, ret);
  }
}
int main() {
  for (int i = 0; i < 20; i++) {
    for (int j = 0; j < 20; j++) {
      for (int k = 0; k < 20; k++) {
        for (int l = 0; l < 20; l++) {
          dist[i][j][k][l] = -1;
        }
      }
    }
  }
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i][j] == '.') {
        DFS(i, j, i, j, 0);
        for (int r = 0; r < n; r++) {
          for (int w = 0; w < m; w++) {
            ans = max(ans, dist[i][j][r][w]);
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
