#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int mp[23][23];
char str[23][23];
int book[23][23];
int ans;
int gx, gy;
int dx[5] = {-1, 1, 0, 0};
int dy[5] = {0, 0, -1, 1};
int n, m;
int qx[4005], qy[4005], step[4005];
int bfs(int sx, int sy, int gx, int gy) {
  memset(book, 0, sizeof(book));
  int head = 0, tail = 0;
  book[sx][sy] = 1;
  qx[head] = sx, qy[tail] = sy, step[tail++] = 0;
  while (head < tail) {
    int x = qx[head], y = qy[head];
    if (x == gx && y == gy) return step[head];
    int nowx, nowy;
    for (int i = 0; i < 4; i++) {
      nowx = x + dx[i], nowy = y + dy[i];
      if (nowx < 0 || nowx >= n || nowy < 0 || nowy >= m) continue;
      if (book[nowx][nowy] == 0 && mp[nowx][nowy] == 0) {
        qx[tail] = nowx, qy[tail] = nowy, step[tail] = step[head] + 1;
        tail++;
      }
    }
    head++;
  }
  return 0;
}
int main() {
  int i, j;
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    scanf("%s", str[i]);
    for (j = 0; j < m; j++) {
      mp[i][j] = str[i][j] == '#';
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (mp[i][j]) continue;
      for (int l = 0; l < n; l++) {
        for (int k = 0; k < m; k++) {
          if (mp[l][k]) continue;
          ans = max(ans, bfs(i, j, l, k));
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
