#include <bits/stdc++.h>
using namespace std;
static const double pi = 3.141592653589793;
using ll = long long;
using Graph = vector<vector<int>>;
int main() {
  ll H, W;
  cin >> H >> W;
  char dp[H][W];
  ll ans = 0;
  for (int i = 0; i < (H); i++) {
    for (int j = 0; j < (W); j++) cin >> dp[i][j];
  }
  queue<pair<int64_t, int64_t>> op;
  for (int i = 0; i < (H); i++) {
    for (int j = 0; j < (W); j++) {
      vector<vector<ll>> num(H, vector<ll>(W));
      vector<vector<ll>> fif(H, vector<ll>(W));
      op.push(pair<int64_t, int64_t>(i, j));
      fif.at(i).at(j) = 1;
      while (op.size() != 0) {
        pair<int64_t, int64_t> p = op.front();
        op.pop();
        ll x = p.first;
        ll y = p.second;
        ll k = num.at(x).at(y) + 1;
        if (x > 0) {
          if (dp[x - 1][y] == '.' & fif.at(x - 1).at(y) == 0) {
            num.at(x - 1).at(y) = k;
            fif.at(x - 1).at(y) = 1;
            op.push(pair<int64_t, int64_t>(x - 1, y));
            ans = max(ans, k);
          }
        }
        if (y > 0) {
          if (dp[x][y - 1] == '.' & fif.at(x).at(y - 1) == 0) {
            num.at(x).at(y - 1) = k;
            fif.at(x).at(y - 1) = 1;
            op.push(pair<int64_t, int64_t>(x, y - 1));
            ans = max(ans, k);
          }
        }
        if (x < H - 1) {
          if (dp[x + 1][y] == '.' & fif.at(x + 1).at(y) == 0) {
            num.at(x + 1).at(y) = k;
            fif.at(x + 1).at(y) = 1;
            op.push(pair<int64_t, int64_t>(x + 1, y));
            ans = max(ans, k);
          }
        }
        if (y < W - 1) {
          if (dp[x][y + 1] == '.' & fif.at(x).at(1 + y) == 0) {
            num.at(x).at(y + 1) = k;
            fif.at(x).at(y + 1) = 1;
            op.push(pair<int64_t, int64_t>(x, y + 1));
            ans = max(ans, k);
          }
        }
      }
    }
  }
  cout << ans;
}
