#include <bits/stdc++.h>
using namespace std;
int MOD = 1000000007;
int modpow(int a, int x) {
  if (a < 0) a += MOD;
  int ans = 1;
  while (x > 0) {
    if (x & 1) ans = ans * a % MOD;
    a = a * a % MOD;
    x >>= 1;
  }
  return ans;
}
int gyaku(int n) { return modpow(n, MOD - 2); }
int h, w;
char s[21][21];
vector<int> a = {1, 0, -1, 0};
vector<int> b = {0, 1, 0, -1};
int dismax;
void dfs(int sx, int sy, vector<vector<int>>& dis) {
  for (int i = 0; i < (int)(4); i++) {
    int dx = a[i], dy = b[i];
    if (s[dx + sx][dy + sy] != '#' && dx + sx < h && dy + sy < w &&
        dx + sx >= 0 && dy + sy >= 0 && dis[dx + sx][dy + sy] == -1) {
      dis[dx + sx][dy + sy] = dis[sx][sy] + 1;
      dismax = max(dis[sx][sy] + 1, dismax);
      dfs(sx + dx, sy + dy, dis);
    }
  }
}
signed main() {
  cin >> h >> w;
  for (int i = 0; i < (int)(h); i++)
    for (int j = 0; j < (int)(w); j++) cin >> s[i][j];
  int ans = 0;
  for (int i = 0; i < (int)(h); i++)
    for (int j = 0; j < (int)(w); j++) {
      int sx = i, sy = j;
      if (s[sx][sy] == '#') break;
      dismax = 0;
      vector<vector<int>> dis(h, vector<int>(w, -1));
      dis[sx][sy] = 0;
      dfs(sx, sy, dis);
      ans = max(ans, dismax);
    }
  cout << ans << endl;
}
