#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9 + 1;
const ll LINF = 1e18 + 1;
const ll MOD = 1e9 + 7;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H, W;
  cin >> H >> W;
  vector<string> grid(H);
  for (int i = 0; i < H; ++i) {
    cin >> grid[i];
  }
  int ans = 0;
  vector<int> dx = {1, 0, -1, 0};
  vector<int> dy = {0, 1, 0, -1};
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      int tmp = 0;
      vector<vector<int>> dist(H, vector<int>(W, INF));
      priority_queue<P, vector<P>, greater<P>> que;
      dist[i][j] = 0;
      que.push(P(0, i * W + j));
      while (!que.empty()) {
        P p = que.top();
        que.pop();
        int d = p.first;
        int x = p.second / W;
        int y = p.second % W;
        if (dist[x][y] < d) continue;
        for (int k = 0; k < 4; ++k) {
          int tx = x + dx[k];
          int ty = y + dy[k];
          if (tx < 0 || tx >= H) continue;
          if (ty < 0 || ty >= W) continue;
          if (grid[tx][ty] == '#') continue;
          if (dist[tx][ty] > d + 1) {
            dist[tx][ty] = d + 1;
            que.push(P(d + 1, tx * W + ty));
          }
        }
      }
      for (int k = 0; k < H; ++k) {
        for (int l = 0; l < W; ++l) {
          if (dist[k][l] == INF) continue;
          tmp = max(tmp, dist[k][l]);
        }
      }
      ans = max(ans, tmp);
    }
  }
  cout << ans << endl;
  return 0;
}
