#include <bits/stdc++.h>
using namespace std;
int dx[4] = {0, 0, -1, 1};
int dy[4] = {-1, 1, 0, 0};
int main() {
  int H, W;
  cin >> H >> W;
  vector<string> S;
  for (int i = 0; i < H; i++) {
    string s;
    cin >> s;
    S.push_back(s);
  }
  int ans = 0;
  for (int sx = 0; sx < H; sx++) {
    for (int sy = 0; sy < W; sy++) {
      int dist[21][21] = {};
      for (int i = 0; i < H; i++)
        for (int j = 0; j < W; j++) dist[i][j] = -1;
      queue<tuple<int, int, int>> que;
      que.emplace(sx, sy, 0);
      while (que.size()) {
        int x_now, y_now, d_now;
        tie(x_now, y_now, d_now) = que.front();
        que.pop();
        if (dist[x_now][y_now] != -1) continue;
        dist[x_now][y_now] = d_now;
        for (int k = 0; k < 4; k++) {
          int x_next = x_now + dx[k], y_next = y_now + dy[k],
              d_next = d_now + 1;
          if (dist[x_next][y_next] != -1 || S[x_next][y_next] == '#') continue;
          que.emplace(x_next, y_next, d_next);
        }
      }
      for (int gx = 0; gx < H; gx++)
        for (int gy = 0; gy < W; gy++) ans = max(ans, dist[gx][gy]);
    }
  }
  cout << ans << endl;
  return 0;
}
