#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using pl = pair<ll, ll>;
using vvb = vector<vector<bool>>;
using vb = vector<bool>;
ll f(ll a, ll b, ll p) {
  if (b == 0) return 1;
  if (b % 2 == 0) {
    ll t = f(a, b / 2, p);
    return t * t % p;
  }
  return a * (f(a, b - 1, p)) % p;
}
signed main() {
  ll n, m;
  cin >> n >> m;
  vl dx = {0, 1, 0, -1};
  vl dy = {1, 0, -1, 0};
  vector<vector<char>> g(n, vector<char>(m));
  for (long long i = 0; i < (long long)(n); i++)
    for (long long j = 0; j < (long long)(m); j++) cin >> g[i][j];
  ll ans = 0;
  for (long long i = 0; i < (long long)(n); i++) {
    for (long long j = 0; j < (long long)(m); j++) {
      vector<vector<bool>> seen(n, vector<bool>(m, 0));
      seen[i][j] = 1;
      queue<pl> q;
      q.push(make_pair(i, j));
      vvl vec(n, vl(m));
      while (!q.empty()) {
        pl p = q.front();
        q.pop();
        ll a, b;
        tie(a, b) = p;
        for (long long k = 0; k < (long long)(4); k++) {
          if (0 <= a + dx[k] && 0 <= b + dy[k] && a + dx[k] < n &&
              b + dy[k] < m) {
            if (seen[a + dx[k]][b + dy[k]]) continue;
            seen[a + dx[k]][b + dy[k]] = 1;
            if (g[a + dx[k]][b + dy[k]] != '#') {
              vec[a + dx[k]][b + dy[k]] = vec[a][b] + 1;
              q.push(make_pair(a + dx[k], b + dy[k]));
            }
          }
        }
      }
      for (long long s = 0; s < (long long)(n); s++)
        for (long long t = 0; t < (long long)(m); t++) chmax(ans, vec[s][t]);
    }
  }
  cout << ans << endl;
  return 0;
}
