#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
vvi dist(20 + 1, vi(20 + 1, 100000));
void bfs(int sh, int sw) {
  int dx[4] = {0, -1, 0, 1}, dy[4] = {-1, 0, 1, 0};
  dist[sh][sw] = 0;
  queue<int> qh, qw;
  qh.push(sh), qw.push(sw);
  while (!qh.empty()) {
    int ph = qh.front(), pw = qw.front();
    qh.pop(), qw.pop();
    for (int k = (0); k < (4); ++k) {
      int h = ph + dy[k], w = pw + dx[k];
      if (dist[h][w] > -1) continue;
      dist[h][w] = dist[ph][pw] + 1;
      qh.push(h), qw.push(w);
    }
  }
}
int main() {
  int H, W;
  cin >> H >> W;
  for (int h = (1); h < (H + 1); ++h) {
    string s;
    cin >> s;
    for (int w = (1); w < (W + 1); ++w)
      if (s[w - 1] == '.') dist[h][w] = -1;
  }
  int ans = 0;
  vvi dist_temp = dist;
  for (int h = (1); h < (H + 1); ++h) {
    for (int w = (1); w < (W + 1); ++w) {
      if (dist_temp[h][w] < 0) {
        dist = dist_temp;
        bfs(h, w);
        for (vi v : dist)
          for (int d : v) ans = max(ans, d == 100000 ? -1 : d);
      }
    }
  }
  cout << ans << endl;
}
