#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = 100000000;
const int MAX_H = 20, MAX_W = 20;
int H, W;
int sy = 0, sx = 0;
int gy = 0, gx = 0;
char maze[MAX_H][MAX_W];
int d[MAX_H][MAX_W];
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int bfs();
int main() {
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> maze[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      for (int k = 0; k < H; k++) {
        for (int l = 0; l < W; l++) {
          if (maze[i][j] == '.') sy = i, sx = j;
          if (maze[k][l] == '.') gy = k, gx = l;
          if (maze[sy][sx] == '#' or maze[gy][gx] == '#') continue;
          if (sy != gy && sx != gx) {
            int now = bfs();
            if (now != INF) ans = max(ans, now);
          }
        }
      }
    }
  }
  cout << ans << endl;
}
int bfs() {
  queue<pair<int, int> > que;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      d[i][j] = INF;
    }
  }
  que.push(pair<int, int>(sy, sx));
  d[sy][sx] = 0;
  while (que.size()) {
    pair<int, int> p = que.front();
    que.pop();
    if (p.first == gy && p.second == gx) {
      break;
    }
    for (int i = 0; i < 4; i++) {
      int ny = p.first + dy[i], nx = p.second + dx[i];
      if (0 <= ny && ny < H && 0 <= nx && nx < W && maze[ny][nx] != '#' &&
          d[ny][nx] == INF) {
        que.push(pair<int, int>(ny, nx));
        d[ny][nx] = d[p.first][p.second] + 1;
      }
    }
  }
  return d[gy][gx];
}
