#include <bits/stdc++.h>
using namespace std;
int H, W;
char s[202][202];
int adj[404][404];
int main() {
  scanf("%d%d", &H, &W);
  for (int i = 0; i < H; ++i) scanf("%s", s[i]);
  memset(adj, 0x3f, sizeof adj);
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      int now = i * W + j;
      int r = i * W + j + 1;
      int d = i * W + j + W;
      if (j != W - 1) {
        adj[r][now] = adj[now][r] = 1;
      }
      if (i != H - 1) {
        adj[d][now] = adj[now][d] = 1;
      }
    }
  }
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      int n = i * W + j;
      if (s[i][j] == '#') {
        for (int k = 0; k < H * W; ++k) adj[n][k] = 0x3f3f3f3f;
      }
    }
  }
  for (int i = 0; i < H * W; ++i) adj[i][i] = 0;
  for (int k = 0; k < H * W; ++k)
    for (int i = 0; i < H * W; ++i)
      for (int j = 0; j < H * W; ++j)
        adj[i][j] = min(adj[i][j], adj[i][k] + adj[k][j]);
  int maxv = 0;
  for (int i = 0; i < H * W; ++i)
    for (int j = 0; j < H * W; ++j) {
      if (adj[i][j] > 30303) continue;
      maxv = max(maxv, adj[i][j]);
    }
  cout << maxv << endl;
}
