#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int> x = {0, 1, 0, -1}, y = {1, 0, -1, 0};
  int H, W;
  cin >> H >> W;
  vector<string> A(H + 2, "");
  for (int i = 0; i < W + 2; i++) {
    A[0] += "#";
    A[H + 1] += "#";
  }
  for (int i = 1; i <= H; i++) {
    string S;
    cin >> S;
    A[i] = "#" + S + "#";
  }
  int l = 0;
  for (int i = 1; i <= H; i++)
    for (int j = 1; j <= W; j++)
      if (A[i][j] == '.') {
        queue<vector<int>> B;
        B.push({i, j, 0});
        vector<vector<bool>> D(H + 2, vector<bool>(W + 2, false));
        int k;
        while (true) {
          vector<int> C = B.front();
          B.pop();
          D[C[0]][C[1]] = true;
          for (int i = 0; i < 4; i++)
            if (A[C[0] + x[i]][C[1] + y[i]] == '.' &&
                !D[C[0] + x[i]][C[1] + y[i]])
              B.push({C[0] + x[i], C[1] + y[i], C[2] + 1});
          if (B.empty()) {
            k = C[2];
            break;
          }
        }
        l = max(k, l);
      }
  cout << l << endl;
}
