#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vvll = vector<vector<ll>>;
using vll = vector<ll>;
vector<ll> dx{0, 1, 0, -1};
vector<ll> dy{1, 0, -1, 0};
int main() {
  ll H, W;
  cin >> H >> W;
  vector<string> route(H);
  vvll dist(H, vll(W, -1));
  for (ll i = 0; i < H; i++) {
    cin >> route[i];
  }
  ll ma = 0;
  for (ll i = 0; i < H; i++) {
    for (ll j = 0; j < W; j++) {
      queue<pll> que;
      dist = vvll(H, vll(W, -1));
      que.push(make_pair(i, j));
      dist[i][j] = 0;
      while (!que.empty()) {
        pll v = que.front();
        que.pop();
        for (ll k = 0; k < 4; k++) {
          ll x = v.first + dx[k];
          ll y = v.second + dy[k];
          if (x < 0 || y < 0 || H <= x || W <= y) continue;
          if (route[x][y] == '#') continue;
          if (dist[x][y] != -1) continue;
          que.push(make_pair(x, y));
          dist[x][y] = dist[v.first][v.second] + 1;
          ma = max(ma, dist[x][y]);
        }
      }
    }
  }
  cout << ma << endl;
  return 0;
}
