#include <bits/stdc++.h>
using namespace std;
const long long dx[] = {1, -1, 0, 0};
const long long dy[] = {0, 0, 1, -1};
long long h, w;
string mp[22];
long long dp[22][22][22][22];
struct Vektor {
  long long y, x;
};
bool ins(long long y, long long x) {
  return 0 <= x && x < w && 0 <= y && y < h;
}
queue<Vektor> q;
void bfs(long long Y, long long X) {
  q.push({Y, X});
  dp[Y][X][Y][X] = 0;
  while (!q.empty()) {
    Vektor now = q.front();
    q.pop();
    for (long long i = 0; i < 4; i++) {
      long long ny = now.y + dy[i];
      long long nx = now.x + dx[i];
      if (ins(ny, nx) && dp[Y][X][ny][nx] == -1 && mp[ny][nx] != '#') {
        dp[Y][X][ny][nx] = dp[Y][X][now.y][now.x] + 1;
        q.push({ny, nx});
      }
    }
  }
}
signed main() {
  cin >> h >> w;
  for (long long i = 0; i < h; i++) {
    cin >> mp[i];
  }
  long long ans = 0;
  memset(dp, -1, sizeof(dp));
  for (long long i = 0; i < h; i++) {
    for (long long j = 0; j < w; j++) {
      bfs(i, j);
      for (long long k = 0; k < h; k++) {
        for (long long l = 0; l < w; l++) {
          ans = max(ans, dp[i][j][k][l]);
        }
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
