#include <bits/stdc++.h>
using namespace std;
int main() {
  long long h, w, dx[4] = {0, 0, -1, +1}, dy[4] = {-1, 1, 0, 0};
  char ch[20][20];
  cin >> h >> w;
  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++) {
    long long r[20][20];
    queue<pair<long long, long long>> q;
    for (long long j = 0; j < h; j++) {
      for (long long k = 0; k < w; k++) {
        r[j][k] = -1;
      }
    }
    for (long long j = 0; j < w; j++) {
      r[i][j] = 0;
      q.push(make_pair(i, j));
      while (q.size() != 0) {
        pair<long long, long long> now = q.front();
        q.pop();
        for (long long i = 0; i < 4; i++) {
          long long nexh = now.first + dx[i];
          long long nexw = now.second + dy[i];
          if (nexh < 0 || nexh >= h || nexw < 0 || nexw >= w) {
            continue;
          }
          if (ch[nexh][nexw] == '#') {
            continue;
          }
          if (r[nexh][nexw] >= 0) {
            continue;
          }
          r[nexh][nexw] = r[now.first][now.second] + 1;
          q.push(make_pair(nexh, nexw));
        }
      }
      for (long long k = 0; k < h; k++) {
        for (long long l = 0; l < w; l++) {
          if (r[k][l] == -1) {
            continue;
          }
          ans = max(r[k][l], ans);
        }
      }
    }
  }
  cout << ans;
  return 0;
}
