#include <bits/stdc++.h>
using namespace std;
const int INF = 100100100;
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
int main() {
  int H, W;
  cin >> H >> W;
  vector<string> s(H);
  for (int ii = 0; ii < H; ++ii) {
    cin >> s[ii];
  }
  int maxScore = 0;
  for (int a = 0; a < H; ++a) {
    for (int b = 0; b < W; ++b) {
      if (s[a][b] == '#') {
        continue;
      }
      vector<vector<int> > dist(H, vector<int>(W, INF));
      queue<pair<int, int> > q;
      dist[a][b] = 0;
      q.push(pair<int, int>(a, b));
      while (!q.empty()) {
        int aa = q.front().first;
        int bb = q.front().second;
        q.pop();
        for (int ii = 0; ii < 4; ++ii) {
          int aaa = aa + di[ii];
          int bbb = bb + dj[ii];
          if (s[aaa][bbb] == '#') {
            continue;
          }
          if (aaa < 0 || aaa >= H || bbb < 0 || bbb >= W) {
            continue;
          }
          if (dist[aaa][bbb] == INF) {
            dist[aaa][bbb] = dist[aa][bb] + 1;
            maxScore = max(maxScore, dist[aaa][bbb]);
            q.push(pair<int, int>(aaa, bbb));
          }
        }
      }
    }
  }
  cout << maxScore << endl;
  return 0;
}
