#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const ll dy[4] = {-1, 0, 1, 0};
const ll dx[4] = {0, 1, 0, -1};
ll bfs(vector<string> &s, ll sy, ll sx, ll gy, ll gx) {
  ll h = s.size(), w = s[0].size();
  vector<vector<ll>> dist(h, vector<ll>(w, INF));
  queue<pair<pair<ll, ll>, ll>> que;
  que.push({{sy, sx}, 0});
  while (!que.empty()) {
    auto tmp = que.front();
    que.pop();
    ll y = tmp.first.first, x = tmp.first.second, d = tmp.second;
    if (y < 0 || y >= h || x < 0 || x >= w || dist[y][x] < d || s[y][x] == '#')
      continue;
    dist[y][x] = d;
    if (gy == y && gx == x) break;
    for (ll i = 0; i < 4; i++) {
      que.push({{y + dy[i], x + dx[i]}, d + 1});
    }
  }
  return dist[gy][gx];
}
int main() {
  ll h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (ll i = 0; i < h; i++) {
    cin >> s[i];
  }
  ll ans = 0;
  for (ll i = 0; i < h; i++) {
    for (ll j = 0; j < w; j++) {
      if (s[i][j] == '#') continue;
      for (ll k = 0; k < h; k++) {
        for (ll l = 0; l < w; l++) {
          if (s[k][l] == '#') continue;
          ans = max(ans, bfs(s, i, j, k, l));
        }
      }
    }
  }
  cout << ans << endl;
}
