#include <bits/stdc++.h>
using namespace std;
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};
const long double PI = acos(-1);
int h, w;
char s[22][22];
vector<vector<int> > d(500, vector<int>(500, (1000000007)));
void solve() {
  cin >> h >> w;
  for (int64_t i = (0); i < (h); i++)
    for (int64_t j = (0); j < (w); j++) cin >> s[i][j];
  for (int64_t i = (0); i < (h); i++)
    for (int64_t j = (0); j < (w); j++) {
      if (s[i][j] == '.') {
        int now = i * h + j;
        d[now][now] = 0;
        for (int64_t k = (0); k < (4); k++) {
          int nx = i + dx[k], ny = j + dy[k];
          if (nx >= 0 && ny >= 0 && nx < h && ny < w)
            if (s[nx][ny] == '.') {
              d[now][nx * h + ny] = 1;
              d[nx * h + ny][now] = 1;
            }
        }
      }
    }
  for (int64_t k = (0); k < (h * w); k++)
    for (int64_t i = (0); i < (h * w); i++)
      for (int64_t j = (0); j < (h * w); j++)
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
  int ans = 0;
  for (int64_t i = (0); i < (h * w); i++)
    for (int64_t j = (0); j < (h * w); j++)
      if (d[i][j] != (1000000007)) ans = max(ans, d[i][j]);
  cout << ans << endl;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}
