#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int H, W;
  cin >> H >> W;
  string M[22];
  for (int i = 0; i < H; i++) {
    cin >> M[i];
  }
  int max_d = -1;
  int x, y;
  for (int sx = 0; sx < W; sx++) {
    for (int sy = 0; sy < H; sy++) {
      queue<tuple<int, int, int> > q;
      q.push(make_tuple(sx, sy, 0));
      int checked[22][22] = {0};
      checked[sx][sy] = 1;
      while (!q.empty()) {
        tuple<int, int, int> t = q.front();
        q.pop();
        for (pair<int, int> p : {make_pair(get<0>(t) - 1, get<1>(t)),
                                 make_pair(get<0>(t) + 1, get<1>(t)),
                                 make_pair(get<0>(t), get<1>(t) - 1),
                                 make_pair(get<0>(t), get<1>(t) + 1)}) {
          x = p.first;
          y = p.second;
          if (x >= 0 && x < W && y >= 0 && y < H) {
            if (M[y][x] == '.' && checked[x][y] == 0) {
              checked[x][y] = 1;
              q.push(make_tuple(x, y, get<2>(t) + 1));
              max_d = max(get<2>(t) + 1, max_d);
            }
          }
        }
      }
    }
  }
  cout << max_d << endl;
  return 0;
}
