#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long long LINF = 1e18;
const pair<int, int> dir[] = {pair<int, int>(0, -1), pair<int, int>(-1, 0),
                              pair<int, int>(0, 1), pair<int, int>(1, 0)};
int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> S(H, vector<char>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> S[i][j];
    }
  }
  int ans;
  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, -1));
      queue<pair<int, int>> q;
      auto update = [&](int i, int j, int x) {
        if (S[i][j] == '#') {
          return;
        }
        if (dist[i][j] != -1) {
          return;
        }
        dist[i][j] = min(x, dist[i][j]);
        q.push(pair<int, int>(i, j));
      };
      update(i, j, 0);
      while (!q.empty()) {
        pair<int, int> p = q.front();
        q.pop();
        for (auto d : dir) {
          int x = p.second + d.first;
          int y = p.first + d.second;
          if (x < 0 || W <= x) continue;
          if (y < 0 || H <= y) continue;
          update(y, x, dist[p.first][p.second] + 1);
        }
      }
      for (int y = 0; y < H; y++) {
        for (int x = 0; x < W; x++) {
          ans = max(ans, dist[y][x]);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
