#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<long long>;
using P = pair<long long, long long>;
int main() {
  ll h, w;
  cin >> h >> w;
  char s[20][20];
  ;
  for (long long i = 0; i < (h); i++) {
    ;
    for (long long j = 0; j < (w); j++) cin >> s[i][j];
  }
  ll dist[20][20];
  queue<P> que;
  ll ans = 0;
  vl dx = {0, 1, 0, -1};
  vl dy = {1, 0, -1, 0};
  ;
  for (long long i = 0; i < (h); i++) {
    ;
    for (long long j = 0; j < (w); j++) {
      if (s[i][j] == '#') continue;
      ;
      for (long long p = 0; p < (h); p++) {
        ;
        for (long long q = 0; q < (w); q++) dist[p][q] = -1;
      }
      que.push(make_pair(i, j));
      dist[i][j] = 0;
      while (!que.empty()) {
        P v = que.front();
        que.pop();
        ;
        for (long long k = 0; k < (3); k++) {
          ll y = v.first + dy[k];
          ll x = v.second + dx[k];
          if (y >= 0 && y < h && x >= 0 && x < w) {
            if (dist[y][x] == -1 && s[y][x] == '.') {
              dist[y][x] = dist[v.first][v.second] + 1;
              que.push(make_pair(y, x));
            }
          }
        }
      }
      ll m = -1;
      ;
      for (long long p = 0; p < (h); p++) {
        ;
        for (long long q = 0; q < (w); q++) m = max(m, dist[p][q]);
      }
      ans = max(m, ans);
    }
  }
  cout << ans << endl;
}
