#include <bits/stdc++.h>
using namespace std;
const int INF = 100000000;
char S[22][22];
int H, W;
int d[22][22];
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int bfs(int sx, int sy, int gx, int gy) {
  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>(sx, sy));
  d[sx][sy] = 0;
  while (que.size()) {
    pair<int, int> p = que.front();
    que.pop();
    if (p.first == gx && p.second == gy) break;
    for (int i = 0; i < 4; i++) {
      int nx = p.first + dx[i], ny = p.second + dy[i];
      if (0 <= nx && nx < H && 0 <= ny && ny < W && S[nx][ny] != '#' &&
          d[nx][ny] == INF) {
        que.push(pair<int, int>(nx, ny));
        d[nx][ny] = d[p.first][p.second] + 1;
      }
    }
  }
  return d[gx][gy];
}
int main() {
  cin >> H >> W;
  int MAX_d = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> S[i][j];
    }
  }
  for (int a = 0; a < H; a++) {
    for (int b = 0; b < W; b++) {
      for (int c = 0; c < H; c++) {
        for (int d = 0; d < W; d++) {
          if (bfs(a, b, c, d) != INF) {
            MAX_d = max(bfs(a, b, c, d), MAX_d);
          }
        }
      }
    }
  }
  cout << MAX_d << endl;
}
