#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1000000007;
const long long int MAX_N = 500010;
const long long int INF = 999999999999;
int dh[] = {-1, 0, 0, 1};
int dw[] = {0, -1, 1, 0};
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < h; i++) cin >> s[i];
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') {
        continue;
      }
      vector<vector<bool> > done(h, vector<bool>(w, false));
      queue<pair<int, pair<int, int> > > q;
      q.push(make_pair(0, pair<int, int>(i, j)));
      while (!q.empty()) {
        pair<int, pair<int, int> > p = q.front();
        q.pop();
        int cost = p.first;
        ans = max(ans, cost);
        int u = p.second.first;
        int v = p.second.second;
        done[u][v] = true;
        for (int d = 0; d < 4; d++) {
          if (u + dh[d] >= 0 && u + dh[d] < h && v + dw[d] >= 0 &&
              v + dw[d] < w && !done[u + dh[d]][v + dw[d]] &&
              s[u + dh[d]][v + dw[d]] == '.') {
            q.push(make_pair(cost + 1, pair<int, int>(u + dh[d], v + dw[d])));
          }
        }
      }
    }
  }
  cout << ans << endl;
}
