#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  char c[21][21];
  int check[21][21];
  int i, j;
  queue<pair<int, int>> que;
  cin >> H >> W;
  int ans = 0;
  for (i = 0; i < H; i++)
    for (j = 0; j < W; j++) {
      cin >> c[i][j];
      check[i][j] = 0;
    }
  for (i = 0; i < H; i++)
    for (j = 0; j < W; j++) {
      que.push(pair<int, int>(i, j));
      while (!que.empty()) {
        int x = que.front().first;
        int y = que.front().second;
        int dx[4] = {1, -1, 0, 0};
        int dy[4] = {0, 0, 1, -1};
        que.pop();
        for (i = 0; i < 4; i++) {
          if (c[x + dx[i]][y + dy[i]] == '.' &&
              check[x + dx[i]][y + dy[i]] < check[x][y] + 1) {
            check[x + dx[i]][y + dy[i]] = check[x][y] + 1;
            que.push(pair<int, int>(x + dx[i], y + dy[i]));
          }
        }
      }
    }
  for (i = 0; i < H; i++)
    for (j = 0; j < W; j++)
      if (check[i][j] > ans) ans = check[i][j];
  cout << ans << endl;
}
