#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using G = vector<vector<int>>;
const int MOD = 1000000007;
const int INF = 1001001001;
const int dy[] = {-1, 0, 1, 0};
const int dx[] = {0, -1, 0, 1};
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (ll i = 0; i < h; ++i) cin >> s[i];
  int ans = 0;
  for (ll i = 0; i < h; ++i) {
    for (ll j = 0; j < w; ++j) {
      if (s[i][j] == '#') continue;
      int f = 0;
      G dist(h, vector<int>(w, -1));
      dist[i][j] == 0;
      queue<P> q;
      q.push({i, j});
      while (!q.empty()) {
        int u = q.front().first;
        int v = q.front().second;
        q.pop();
        for (ll k = 0; k < 4; ++k) {
          int y = u + dy[k];
          int x = v + dx[k];
          if (y < 0 || y >= h || x < 0 || x >= w) continue;
          if (s[y][x] == '#') continue;
          if (dist[y][x] != -1) continue;
          dist[y][x] = dist[u][v] + 1;
          f = max(f, dist[y][x]);
          q.push({y, x});
        }
      }
      ans = max(ans, f);
    }
  }
  if (ans == 0) {
    cout << ans << endl;
    return 0;
  }
  ++ans;
  cout << ans << endl;
  return 0;
}
