#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<ll>>;
using P = pair<ll, ll>;
vector<char> dx = {0, -1, 0, 1};
vector<char> dy = {-1, 0, 1, 0};
ll H, W;
ll dist[30][30];
void dijkstra(vector<string> &S, ll y, ll x) {
  for (ll dir = 0; dir < 4; dir++) {
    ll ny = y + dy.at(dir);
    ll nx = x + dx.at(dir);
    if (ny < 0 || nx < 0 || ny >= H || nx >= W) continue;
    if (dist[ny][nx] != 1000000000000) {
      if (dist[ny][nx] < dist[y][x] + 1) continue;
    }
    if (S.at(ny).at(nx) == '#') continue;
    dist[ny][nx] = dist[y][x] + 1;
    dijkstra(S, ny, nx);
  }
}
int main() {
  ll ans = 0;
  cin >> H >> W;
  vector<string> S(H);
  for (ll i = 0; i < (ll)(H); i++) cin >> S.at(i);
  for (ll i = 0; i < (ll)(H); i++)
    for (ll j = 0; j < (ll)(W); j++) {
      if (S.at(i).at(j) == '#') continue;
      for (ll k = 0; k < (ll)(H); k++)
        for (ll l = 0; l < (ll)(W); l++) dist[k][l] = 1000000000000;
      dist[i][j] = 0;
      dijkstra(S, i, j);
      ll tmp = 0;
      for (ll i = 0; i < (ll)(H); i++)
        for (ll j = 0; j < (ll)(W); j++)
          if (dist[i][j] != 1000000000000) tmp = max(tmp, dist[i][j]);
      ans = max(ans, tmp);
    }
  cout << ans << endl;
  return 0;
}
