#include <bits/stdc++.h>
using namespace std;
int a[(1 << 9)][(1 << 9)];
int h, w;
int m[(1 << 9)][(1 << 9)];
int n;
int ind(int x, int y) { return (x - 1) * w + (y - 1); }
void addedge(int cur, int x, int y) {
  if (!m[x][y]) {
    return;
  }
  int nnext = ind(x, y);
  a[cur][nnext] = 1;
  a[nnext][cur] = 1;
}
void addedges(int x, int y) {
  if (!m[x][y]) {
    return;
  }
  int cur = ind(x, y);
  addedge(cur, x + 1, y);
  addedge(cur, x - 1, y);
  addedge(cur, x, y - 1);
  addedge(cur, x, y + 1);
}
void floyd() {
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (a[i][j] > a[i][k] + a[k][j]) {
          a[i][j] = a[i][k] + a[k][j];
        }
      }
    }
  }
}
int main() {
  memset(a, 63, sizeof(a));
  scanf("%d %d\n", &h, &w);
  for (int i = 1; i <= h; i++) {
    char s[(1 << 9)];
    gets(s);
    for (int j = 1; j <= w; j++) {
      if (s[j - 1] == '.') {
        m[i][j] = 1;
      }
    }
  }
  n = h * w;
  for (int i = 0; i < n; i++) {
    a[i][i] = 0;
  }
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      addedges(i, j);
    }
  }
  floyd();
  int ret = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if ((a[i][j] < (1 << 29)) && (a[i][j] > ret)) {
        ret = a[i][j];
      }
    }
  }
  cout << ret << endl;
  return 0;
}
