#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
long long mpow(long long x, long long n) {
  long long ans = 1;
  while (n != 0) {
    if (n & 1) ans = ans * x % MOD;
    x = x * x % MOD;
    n = n >> 1;
  }
  return ans;
}
int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> M(H, vector<char>(W, 0));
  for (int i = 0; i < H; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < W; j++) {
      M.at(i).at(j) = s.at(j);
    }
  }
  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      vector<vector<int>> dist(H, vector<int>(W, MOD));
      queue<pair<int, int>> Q;
      dist.at(i).at(j) = 0;
      Q.push(make_pair(i, j));
      while (!Q.empty()) {
        int qx = Q.front().first, qy = Q.front().second;
        Q.pop();
        int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
        for (int k = 0; k < 4; k++) {
          int x = qx + dx[k], y = qy + dy[k];
          if (x < 0 || H <= x || y < 0 || W <= y) continue;
          if (M.at(x).at(y) != '.' || dist.at(x).at(y) < MOD) continue;
          Q.push(make_pair(x, y));
          dist.at(x).at(y) = dist.at(qx).at(qy) + 1;
          ans = max(ans, dist.at(x).at(y));
        }
      }
    }
  }
  cout << ans << endl;
}
