#include <bits/stdc++.h>
const int INF = 1001001001;
using namespace std;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int dist[21][21];
int H, W;
char S[21][21];
int res;
void clean() {
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      dist[i][j] = INF;
    }
  }
  return;
}
int bfs(int xs, int ys, int xg, int yg) {
  queue<pair<int, int> > que;
  clean();
  que.push(pair<int, int>(ys, xs));
  dist[ys][xs] = 0;
  while (que.size()) {
    pair<int, int> p = que.front();
    que.pop();
    int x0 = p.second;
    int y0 = p.first;
    if (y0 == yg && x0 == xg) break;
    for (int i = 0; i < 4; i++) {
      int x = x0 + dx[i];
      int y = y0 + dy[i];
      if (0 <= x && x <= W - 1 && 0 <= y && y <= H - 1) {
        if (S[y][x] == '.' && dist[y][x] == INF) {
          que.push(pair<int, int>(y, x));
          dist[y][x] = dist[y0][x0] + 1;
        }
      }
    }
  }
  return dist[yg][xg];
}
int main() {
  cin >> H >> W;
  for (int i = 0; i < H; i++) cin >> S[i];
  res = 0;
  for (int sy = 0; sy < H; sy++) {
    for (int sx = 0; sx < W; sx++) {
      for (int gy = 0; gy < H; gy++) {
        for (int gx = 0; gx < W; gx++) {
          clean();
          int num = bfs(sx, sy, gx, gy);
          if (num < INF) res = max(res, num);
        }
      }
    }
  }
  cout << res << endl;
}
