#include <bits/stdc++.h>
using namespace std;
const int b = 22, dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
string in[b];
int far[b][b];
int n, m, ans = -1;
pair<int, int> a;
int bfs() {
  deque<pair<int, int> > p;
  memset(far, -1, sizeof(far));
  p.push_back(a);
  far[a.first][a.second] = 0;
  while (!p.empty()) {
    pair<int, int> now = p[0];
    p.pop_front();
    int x = now.first, y = now.second;
    for (int i = 0; i < 4; i++) {
      int xx = x + dx[i], yy = y + dy[i];
      if (xx < 0 || yy < 0 || yy >= m || xx >= n || in[xx][yy] == '#') continue;
      if (far[xx][yy] == -1) {
        p.push_back(make_pair(xx, yy));
        far[xx][yy] = far[x][y] + 1;
      }
    }
  }
  int ans2 = 0;
  for (int i = 0; i < n; i++)
    for (int c = 0; c < m; c++) ans2 = max(ans2, far[i][c]);
  return ans2;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> in[i];
  for (int i = 0; i < n; i++) {
    for (int c = 0; c < m; c++) {
      if (in[i][c] != '#') {
        a = make_pair(i, c);
        int now = bfs();
        now = bfs();
        cout << now << endl;
        return 0;
      }
    }
  }
  return 0;
}
