#include <bits/stdc++.h>
using namespace std;
int H, W;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
void bfs(vector<string> &G, vector<vector<int>> &seen,
         queue<pair<int, int>> &q) {
  while (!q.empty()) {
    auto now = q.front();
    q.pop();
    for (int i = 0; i < 4; i++) {
      int nh = now.first + dx[i];
      int nw = now.second + dy[i];
      if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
      if (G[nh][nw] == '#' || seen[nh][nw] != -1) continue;
      q.push(make_pair(nh, nw));
      seen[nh][nw] = seen[now.first][now.second] + 1;
    }
  }
}
int main() {
  cin >> H >> W;
  vector<string> G(H);
  for (int i = 0; i < H; i++) cin >> G[i];
  int ans = 0;
  vector<vector<int>> seen;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      seen.assign(H, vector<int>(W, -1));
      seen[i][j] = 0;
      queue<pair<int, int>> q;
      q.push(make_pair(i, j));
      bfs(G, seen, q);
      for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
          ans = max(ans, seen[i][j]);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
