#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long long mod = 1e9 + 7;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
int bfs(string s[], int h, int w) {
  int ans = 0;
  for (int x = 0; x < (h); ++x)
    for (int y = 0; y < (w); ++y) {
      if (s[x][y] == '#') continue;
      vector<vector<int>> dist(h, vector<int>(w, INF));
      queue<pair<int, int>> q;
      auto update = [&](int i, int j, int x) {
        if (dist[i][j] != INF) return;
        dist[i][j] = x;
        q.push(pair<int, int>(i, j));
      };
      update(x, y, 0);
      while (!q.empty()) {
        int i = q.front().first;
        int j = q.front().second;
        for (int dir = 0; dir < (4); ++dir) {
          int ni = i + dx[dir], nj = j + dy[dir];
          if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
          if (s[ni][nj] == '#') continue;
          update(ni, nj, dist[i][j] + 1);
        }
      }
      for (int i = 0; i < (h); ++i)
        for (int j = 0; j < (w); ++j) {
          if (dist[i][j] == INF) continue;
          ans = max(ans, dist[i][j]);
        }
    }
  return ans;
}
int main() {
  int h, w;
  cin >> h >> w;
  string meiro[h];
  for (int i = 0; i < (h); ++i) cin >> meiro[i];
  int ans = bfs(meiro, h, w);
  cout << ans << endl;
  return 0;
}
