#include <bits/stdc++.h>
using namespace std;
inline int read() {
  char ch = getchar();
  int nega = 1;
  while (!isdigit(ch)) {
    if (ch == '-') nega = -1;
    ch = getchar();
  }
  int ans = 0;
  while (isdigit(ch)) {
    ans = ans * 10 + ch - 48;
    ch = getchar();
  }
  if (nega == -1) return -ans;
  return ans;
}
char a[25][25];
int dep[25][25];
int dx[] = {0, 1, -1, 0, 0};
int dy[] = {0, 0, 0, 1, -1};
int n, m;
int sol(int sx, int sy, int ex, int ey) {
  queue<pair<int, int> > q;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      dep[i][j] = 1000;
    }
  }
  dep[sx][sy] = 0;
  q.push(make_pair(sx, sy));
  while (!q.empty()) {
    pair<int, int> u = q.front();
    q.pop();
    if (u.first == ex && u.second == ey) return dep[ex][ey];
    for (int i = 1; i <= 4; i++) {
      int tx = u.first + dx[i], ty = u.second + dy[i];
      if (tx < 1 || ty < 1 || tx > n || ty > m) continue;
      if (a[tx][ty] == '#') continue;
      dep[tx][ty] = dep[u.first][u.second] + 1;
      q.push(make_pair(tx, ty));
    }
  }
}
signed main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    scanf("%s", a[i] + 1);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (a[i][j] == '#') continue;
      for (int c = 1; c <= n; c++) {
        for (int d = 1; d <= m; d++) {
          if (a[c][d] == '#') continue;
          if (c == i && d == j) continue;
          ans = max(ans, sol(i, j, c, d));
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
