#include <bits/stdc++.h>
using namespace std;
const int maxm = (412);
int dis[maxm][maxm], h, w, cnt[21][21], mx, cn;
char s[21][21];
int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) cnt[i][j] = cn++;
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> s[i][j];
    }
  }
  for (int i = 0; i < cn; i++) {
    for (int j = 0; j < cn; j++) {
      dis[i][j] = 1e9;
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') continue;
      int now = cnt[i][j];
      if (i > 0) {
        if (s[i - 1][j] != '#')
          dis[now][cnt[i - 1][j]] = dis[cnt[i - 1][j]][now] = 1;
      }
      if (i + 1 < h) {
        if (s[i + 1][j] != '#')
          dis[now][cnt[i + 1][j]] = dis[cnt[i + 1][j]][now] = 1;
      }
      if (j > 0) {
        if (s[i][j - 1] != '#')
          dis[now][cnt[i][j - 1]] = dis[cnt[i][j - 1]][now] = 1;
      }
      if (j + 1 < w) {
        if (s[i][j + 1] != '#')
          dis[now][cnt[i][j + 1]] = dis[cnt[i][j + 1]][now] = 1;
      }
    }
  }
  for (int i = 0; i < cn; i++) {
    for (int j = 0; j < cn; j++) {
      for (int k = 0; k < cn; k++) {
        if (dis[i][j] > dis[i][k] + dis[k][j])
          dis[i][j] = dis[k][j] + dis[i][k];
        if (dis[j][i] > dis[i][k] + dis[k][j])
          dis[j][i] = dis[i][k] + dis[k][j];
      }
    }
  }
  for (int i = 0; i < cn; i++) {
    for (int j = 0; j < cn; j++) {
      if (dis[i][j] != 1e9) {
        mx = max(dis[i][j], mx);
      }
    }
  }
  cout << mx;
  return 0;
}
