#include <bits/stdc++.h>
using namespace std;
long long INF = 1e9 + 7;
const long long dx[4] = {1, 0, -1, 0};
const long long dy[4] = {0, 1, 0, -1};
long long H, W;
void bfs(vector<string> &S, long long X, long long Y,
         vector<vector<long long>> &ok, long long &cnt) {
  queue<pair<long long, long long>> que;
  que.push(make_pair(X, Y));
  while (!que.empty()) {
    long long x = que.front().first;
    long long y = que.front().second;
    que.pop();
    cnt = max(cnt, ok[x][y]);
    for (long long i = 0; i < 4; i++) {
      long long nx = x + dx[i];
      long long ny = y + dy[i];
      if (!(nx < 0 || nx >= H || ny < 0 || ny >= W)) {
        if (S[nx][ny] == '.') {
          if (ok[nx][ny] == 0) {
            ok[nx][ny] = ok[x][y] + 1;
            que.push(make_pair(nx, ny));
          }
        }
      }
    }
  }
  return;
}
signed main() {
  cin >> H >> W;
  vector<string> S(H);
  for (long long i = 0; i < H; i++) {
    cin >> S[i];
  }
  long long ans = 0;
  for (long long i = 0; i < H; i++) {
    for (long long j = 0; j < W; j++) {
      if (S[i][j] == '.') {
        long long cnt = 0;
        vector<vector<long long>> ok(H, vector<long long>(W, 0));
        bfs(S, i, j, ok, cnt);
        ans = max(ans, cnt);
      }
    }
  }
  cout << ans << endl;
}
