#include <bits/stdc++.h>
using namespace std;
char mp[22][22];
long long dist[22 * 22][22 * 22];
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
  for (long long(i) = (0); (i) < (22); ++i)
    for (long long(j) = (0); (j) < (22); ++j) mp[i][j] = '#';
  for (long long(i) = (0); (i) < (22 * 22); ++i)
    for (long long(j) = (0); (j) < (22 * 22); ++j) dist[i][j] = 1000000000;
  long long h, w;
  cin >> h >> w;
  for (long long(i) = (0); (i) < (h); ++i) {
    for (long long(j) = (0); (j) < (w); ++j) {
      cin >> mp[i + 1][j + 1];
    }
  }
  for (long long(i) = (0); (i) < (h); ++i) {
    for (long long(j) = (0); (j) < (w); ++j) {
      int x = j + 1;
      int y = i + 1;
      if (mp[y][x] == '#') continue;
      for (long long(k) = (0); (k) < (4); ++k) {
        int xx = x + dx[k];
        int yy = y + dy[k];
        if (mp[yy][xx] == '.') {
          dist[y * (h + 2) + x][yy * (h + 2) + xx] = 1;
          dist[yy * (h + 2) + xx][y * (h + 2) + x] = 1;
        }
      }
    }
  }
  for (long long(k) = (0); (k) < (22 * 22); ++k)
    for (long long(i) = (0); (i) < (22 * 22); ++i)
      for (long long(j) = (0); (j) < (22 * 22); ++j) {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
  long long ans = 0;
  for (long long(i) = (0); (i) < (22 * 22); ++i)
    for (long long(j) = (0); (j) < (22 * 22); ++j) {
      if (dist[i][j] != 1000000000) {
        ans = max(ans, dist[i][j]);
      }
    }
  cout << ans << endl;
  return 0;
}
