#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
const int MAX = 510000;
const int MOD = 1000000007;
ll gcd(ll a, ll b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
long long com(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
  int h, w;
  cin >> h >> w;
  char s[h][w];
  for (int(i) = 0; (i) < (h); (i)++) {
    for (int(j) = 0; (j) < (w); (j)++) {
      cin >> s[i][j];
    }
  }
  int M = -1;
  for (int(i) = 0; (i) < (h); (i)++) {
    for (int(j) = 0; (j) < (w); (j)++) {
      if (s[i][j] == '#') continue;
      vector<vector<int>> sikaku(h, vector<int>(w, -1));
      queue<pair<int, int>> que;
      sikaku[i][j] = 0;
      que.push(make_pair(i, j));
      int saidai = 0;
      while (!que.empty()) {
        int fi = (que.front()).first;
        int se = que.front().second;
        que.pop();
        if ((fi - 1 >= 0) && (s[fi - 1][se] == '.') &&
            (sikaku[fi - 1][se] == -1)) {
          sikaku[fi - 1][se] = sikaku[fi][se] + 1;
          saidai = max(saidai, sikaku[fi - 1][se]);
          que.push(make_pair(fi - 1, se));
        }
        if ((fi + 1 <= w - 1) && (s[fi + 1][se] == '.') &&
            (sikaku[fi + 1][se] == -1)) {
          sikaku[fi + 1][se] = sikaku[fi][se] + 1;
          saidai = max(saidai, sikaku[fi + 1][se]);
          que.push(make_pair(fi + 1, se));
        }
        if ((se - 1 >= 0) && (s[fi][se - 1] == '.') &&
            (sikaku[fi][se - 1] == -1)) {
          sikaku[fi][se - 1] = sikaku[fi][se] + 1;
          saidai = max(saidai, sikaku[fi][se - 1]);
          que.push(make_pair(fi, se - 1));
        }
        if ((se + 1 <= h - 1) && (s[fi][se + 1] == '.') &&
            (sikaku[fi][se + 1] == -1)) {
          sikaku[fi][se + 1] = sikaku[fi][se] + 1;
          saidai = max(saidai, sikaku[fi][se + 1]);
          que.push(make_pair(fi, se + 1));
        }
      }
      M = max(M, saidai);
    }
  }
  cout << M << endl;
}
