#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = 1001001001;
int H, W;
int d[30][30];
char maze[30][30];
int dh[4] = {1, 0, -1, 0};
int dw[4] = {0, 1, 0, -1};
int bfs(int sh, int sw) {
  queue<int> ph;
  queue<int> pw;
  for (int i = 0; i < (H); ++i)
    for (int j = 0; j < (W); ++j) d[i][j] = INF;
  d[sh][sw] = 0;
  ph.push(sh);
  pw.push(sw);
  while (ph.size()) {
    int h = ph.front();
    int w = pw.front();
    ph.pop();
    pw.pop();
    for (int i = 0; i < 4; i++) {
      int nh = h + dh[i];
      int nw = w + dw[i];
      if (0 <= nh and nh < H and 0 <= nw and nw < W && maze[nh][nw] != '#' &&
          d[nh][nw] == INF) {
        ph.push(nh);
        pw.push(nw);
        d[nh][nw] = d[h][w] + 1;
      }
    }
  }
  int ret = 0;
  for (int i = 0; i < (H); ++i)
    for (int j = 0; j < (W); ++j) {
      if (d[i][j] != INF) {
        ret = max(ret, d[i][j]);
      }
    }
  return ret;
}
int main() {
  cin >> H >> W;
  for (int i = 0; i < (H); ++i) cin >> maze[i];
  int ans = 0;
  for (int i = 0; i < (H); ++i)
    for (int j = 0; j < (W); ++j) {
      ans = max(ans, bfs(i, j));
    }
  cout << ans << endl;
}
