#include <bits/stdc++.h>
using namespace std;
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.at(i).at(j);
    }
  }
  int ans = 0;
  int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
  for (int sy = 0; sy < H; sy++) {
    for (int sx = 0; sx < W; sx++) {
      if (S.at(sy).at(sx) == '#') continue;
      vector<vector<int>> dis(H, vector<int>(W, 0));
      vector<vector<bool>> check(H, vector<bool>(W, true));
      queue<pair<int, int>> Q;
      Q.push(make_pair(sy, sx));
      while (!Q.empty()) {
        pair<int, int> q = Q.front();
        Q.pop();
        for (int i = 0; i < 4; i++) {
          int Y = q.first + dy[i];
          int X = q.second + dx[i];
          if (Y < 0 || Y >= H) continue;
          if (X < 0 || X >= W) continue;
          if (S.at(Y).at(X) == '#') continue;
          if (check.at(Y).at(X)) {
            dis.at(Y).at(X) = dis.at(q.first).at(q.second) + 1;
            Q.push(make_pair(Y, X));
            check.at(Y).at(X) = false;
          }
        }
      }
      for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
          ans = max(ans, dis.at(i).at(j));
        }
      }
    }
  }
  cout << ans << endl;
}
