#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
vector<int> di = {-1, 0, 1, 0};
vector<int> dj = {0, 1, 0, -1};
int main() {
  int H, W;
  cin >> H >> W;
  int ans = 0;
  vector<string> S(H);
  for (int i = 0; i < H; i++) cin >> S[i];
  for (int i = 0; i < H; i++)
    for (int j = 0; j < W; j++) {
      if (S[i][j] == '#') continue;
      vector<vector<int>> dist(H, vector<int>(W, 1001001001));
      queue<P> q;
      auto update = [&](int ii, int jj, int x) {
        if (dist[ii][jj] != 1001001001) return;
        dist[ii][jj] = x;
        q.push(P(ii, jj));
      };
      update(i, j, 0);
      while (!q.empty()) {
        int si = q.front().first;
        int sj = q.front().second;
        q.pop();
        for (int dif = 0; i < 4; i++) {
          int tgt_x = si + di[dif];
          int tgt_y = sj + dj[dif];
          if (tgt_x < 0 || tgt_x >= W || tgt_y < 0 || tgt_y >= H) continue;
          if (S[tgt_x][tgt_y] == '#') continue;
          update(tgt_x, tgt_y, dist[si][sj] + 1);
        }
      }
      for (int ni = 0; ni < H; ni++)
        for (int nj = 0; nj < W; nj++) {
          if (dist[ni][nj] == 1001001001) continue;
          if (dist[ni][nj] > ans) ans = dist[ni][nj];
        }
    }
  cout << ans << endl;
  return 0;
}
