#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long mod = 1e9 + 7;
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 P = pair<int, int>;
struct Corr {
  ll y;
  ll x;
  ll depth;
};
ll N, M;
ll s_y, s_x, g_y, g_x;
ll y, x, depth;
vector<string> vect;
queue<Corr> q;
vector<ll> y_vec = {0, 0, -1, +1};
vector<ll> x_vec = {-1, +1, 0, 0};
ll bfs() {
  ll ret = 0;
  while (!q.empty()) {
    Corr now = q.front();
    q.pop();
    y = now.y, x = now.x, depth = now.depth;
    for (ll i = 0; i < 4; ++i) {
      Corr next = {y + y_vec[i], x + x_vec[i], depth + 1};
      if (0 <= next.y && next.y <= N - 1 && 0 <= next.x && next.x <= M - 1 &&
          vect[next.y][next.x] == '.') {
        vect[next.y][next.x] = 'x';
        q.push(next);
        chmax(ret, depth);
      }
    }
  }
  return ret;
}
int main() {
  cin >> N >> M;
  ll ans = 0;
  vector<string> vectcp;
  vectcp.resize(N);
  for (ll i = 0; i < N; ++i) cin >> vectcp[i];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      if (vectcp[i][j] == '#') continue;
      vect = vectcp;
      s_y = i;
      s_x = j;
      Corr start = {s_y, s_x, 0};
      q.emplace(start);
      chmax(ans, bfs());
    }
  }
  cout << ans + 1 << endl;
  return 0;
}
