#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;
template <typename T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
template <typename T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
template <typename T>
map<T, T> primeFactor(T n) {
  map<T, T> res;
  for (T i = 2; i * i <= n; ++i) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n] = 1;
  return res;
}
template <typename T>
bool IsPrimeNumber(T num) {
  if (num <= 2)
    return true;
  else if (num % 2 == 0)
    return false;
  double sqrtNum = sqrt(num);
  for (int i = 3; i <= sqrtNum; i += 2) {
    if (num % i == 0) {
      return false;
    }
  }
  return true;
}
long long modinv(long long a, long long m) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}
int main() {
  ll h, w, ans = 0;
  std::cin >> h >> w;
  vector<string> s(h), t(h);
  for (ll i = 0; i < h; i++) {
    std::cin >> s[i];
  }
  for (ll i = 0; i < h; i++) {
    for (ll j = 0; j < w; j++) {
      t = s;
      queue<ll> q;
      q.push(i * 100 + j);
      ll cnt = 0;
      while (q.size() > 0) {
        ans = max(ans, cnt);
        queue<ll> r;
        while (q.size() > 0) {
          ll x = q.front() / 100;
          ll y = q.front() % 100;
          q.pop();
          if (x - 1 >= 0 && t[x - 1][y] == '.') {
            r.push((x - 1) * 100 + y);
            t[x - 1][y] = '#';
          }
          if (x + 1 < h && t[x + 1][y] == '.') {
            r.push((x + 1) * 100 + y);
            t[x + 1][y] = '#';
          }
          if (y - 1 >= 0 && t[x][y - 1] == '.') {
            r.push(x * 100 + (y - 1));
            t[x][y - 1] = '#';
          }
          if (y + 1 >= 0 && t[x][y + 1] == '.') {
            r.push(x * 100 + (y + 1));
            t[x][y + 1] = '#';
          }
        }
        q = r;
        cnt++;
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
