#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll H, W;
ll WALL = -1;
ll BFS(vector<ll> cost, ll start) {
  vector<ll> dist = {1, -1, W, -W};
  queue<ll> que;
  que.push(start);
  cost[start] = 0;
  ll ans = 0;
  while (!que.empty()) {
    ll q = que.front();
    que.pop();
    for (ll(i) = (0); (i) < (dist.size()); ++(i)) {
      ll next = q + dist[i];
      if ((next >= 0) && (next < H * W) &&
          !(((q + 1) % W == 0) && next % W == 0) &&
          !(q % W == 0 && (next + 1) % W == 0)) {
        if (cost[next] == INT_MAX) {
          cost[next] = cost[q] + 1;
          ans = max(ans, cost[next]);
          que.push(next);
        }
      }
    }
  }
  return ans;
}
int main(void) {
  cin >> H >> W;
  char s;
  vector<ll> cost(H * W, INT_MAX);
  for (ll(i) = (0); (i) < (H * W); ++(i)) {
    cin >> s;
    if (s == '#') cost[i] = WALL;
  }
  ll ans = 0;
  for (ll(i) = (0); (i) < (H * W); ++(i)) {
    ans = max(ans, BFS(cost, i));
  }
  cout << ans << endl;
}
