#include <bits/stdc++.h>
using namespace std;
int main() {
  long long H, W;
  cin >> H >> W;
  vector<long long> row(W + 2, -1);
  vector<vector<long long>> M(H + 2, row);
  vector<vector<long long>> X;
  for (long long h = 0; h < H; ++h) {
    string s;
    cin >> s;
    for (long long w = 0; w < W; ++w) {
      if (s[w] == '#') continue;
      M[h + 1][w + 1] = 0;
      vector<long long> x = {h + 1, w + 1};
      X.push_back(x);
    }
  }
  long long mark = 0, ans = 0;
  for (long long ist = 0; ist < X.size(); ++ist)
    for (long long igl = ist + 1; igl < X.size(); ++igl) {
      ++mark;
      long long turn = 0;
      bool f = false;
      vector<vector<long long>> queue = {X[ist]};
      while (queue.size() && !f) {
        vector<vector<long long>> queue_new;
        for (long long iq = 0; iq < queue.size(); ++iq) {
          long long qx = queue[iq][0], qy = queue[iq][1];
          if (qx == X[igl][0] && qy == X[igl][1]) {
            f = true;
            break;
          }
          long long x, y, m;
          x = qx + 1;
          y = qy;
          m = M[x][y];
          if (m != -1 and m != mark) {
            M[x][y] = mark;
            vector<long long> xx = {x, y};
            queue_new.push_back(xx);
          }
          x = qx - 1;
          y = qy;
          m = M[x][y];
          if (m != -1 and m != mark) {
            M[x][y] = mark;
            vector<long long> xx = {x, y};
            queue_new.push_back(xx);
          }
          x = qx;
          y = qy + 1;
          m = M[x][y];
          if (m != -1 and m != mark) {
            M[x][y] = mark;
            vector<long long> xx = {x, y};
            queue_new.push_back(xx);
          }
          x = qx;
          y = qy - 1;
          m = M[x][y];
          if (m != -1 and m != mark) {
            M[x][y] = mark;
            vector<long long> xx = {x, y};
            queue_new.push_back(xx);
          }
        }
        queue = queue_new;
        ++turn;
      }
      ans = max(ans, turn - 1);
    }
  cout << ans << endl;
  return 0;
}
