#include <bits/stdc++.h>
using namespace std;
const vector<int> dx = {1, -1, 0, 0}, dy = {0, 0, 1, -1};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  for (int i = 0; i < H; i++) {
    cin >> S[i];
  }
  int res = 0;
  auto f = [S, H, W](int sy, int sx) {
    vector<vector<int>> G(H, vector<int>(W, -1));
    G[sy][sx] = 0;
    queue<pair<int, int>> que;
    que.push(make_pair(sy, sx));
    int res = 0;
    while (!que.empty()) {
      auto q = que.front();
      que.pop();
      int y = q.first, x = q.second;
      for (int i = 0; i < 4; i++) {
        int ny = y + dy[i], nx = x + dx[i];
        if (ny < 0 || ny >= H || nx < 0 || nx >= W) continue;
        if (G[ny][nx] != -1 || S[ny][nx] == '#') continue;
        G[ny][nx] = G[y][x] + 1;
        que.push(make_pair(ny, nx));
        res = max(res, G[ny][nx]);
      }
    }
    return res;
  };
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      res = max(res, f(i, j));
    }
  }
  cout << res << '\n';
  return 0;
}
