#include <bits/stdc++.h>
using namespace std;
int main() {
  long long h, w;
  cin >> h >> w;
  long long dx[4] = {1, 0, -1, 0};
  long long dy[4] = {0, 1, 0, -1};
  char ch[22][22];
  for (long long i = 0; i < h; i++) {
    for (long long j = 0; j < w; j++) {
      cin >> ch[i][j];
    }
  }
  long long ans = 0;
  for (long long i = 0; i < h; i++) {
    for (long long j = 0; j < w; j++) {
      long long cnt[22][22];
      for (long long i = 0; i < h; i++) {
        for (long long j = 0; j < w; j++) {
          cnt[i][j] = 0;
        }
      }
      if (ch[i][j] == '#') {
        continue;
      }
      cnt[i][j] = 1;
      queue<pair<long long, long long>> q;
      q.push(make_pair(i, j));
      while (q.size() != 0) {
        long long nowx = q.front().first;
        long long nowy = q.front().second;
        q.pop();
        for (long long i = 0; i < 4; i++) {
          long long nexx = nowx + dx[i];
          long long nexy = nowy + dy[i];
          if (ch[nexx][nexy] == '#') {
            continue;
          }
          if (cnt[nexx][nexy] != 0) {
            continue;
          }
          cnt[nexx][nexy] = cnt[nowx][nowy] + 1;
          q.push(make_pair(nexx, nexy));
        }
      }
      for (long long i = 0; i < h; i++) {
        for (long long j = 0; j < w; j++) {
          ans = max(ans, cnt[i][j]);
        }
      }
    }
  }
  cout << ans - 1;
  return 0;
}
