#include <bits/stdc++.h>
using namespace std;
const long long dx[4] = {1, 0, -1, 0};
const long long dy[4] = {0, 1, 0, -1};
long long H, W;
vector<string> s;
bool seen[21][21];
long long ans;
void dfs(long long h, long long w, long long d) {
  seen[h][w] = true;
  ans = max(ans, d);
  for (long long dir = 0; dir < 4; ++dir) {
    long long nh = h + dx[dir];
    long long nw = w + dy[dir];
    long long nd = d + 1;
    if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
    if (s[nh][nw] == '#') {
      continue;
    }
    if (seen[nh][nw]) {
      continue;
    }
    dfs(nh, nw, nd);
  }
}
signed main() {
  cout << fixed << setprecision(10);
  cerr << fixed << setprecision(10);
  cin >> H >> W;
  s.resize(H);
  ans = 0;
  for (long long i = (0); i < (H); i++) cin >> s[i];
  for (long long i = (0); i < (H); i++) {
    for (long long j = (0); j < (W); j++) {
      if (s[i][j] == '.') {
        memset(seen, 0, sizeof(seen));
        dfs(i, j, 0);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
