#include <bits/stdc++.h>
using namespace std;
const int mod = 1e+9 + 7;
const int dy[4] = {1, 0, -1, 0};
const int dx[4] = {0, 1, 0, -1};
int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> a(H, vector<char>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) cin >> a[i][j];
  }
  int mx = 0;
  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      mx = 0;
      vector<vector<int>> dist(H, vector<int>(W, -1));
      dist[i][j] = 0;
      queue<pair<int, int>> q;
      q.push(make_pair(i, j));
      while (!q.empty()) {
        long long y = q.front().first, x = q.front().second;
        q.pop();
        for (int k = 0; k < 4; k++) {
          long long ny = y + dy[k], nx = x + dx[k];
          if (ny < 0 || nx < 0 || ny >= H || nx >= W) continue;
          if (a[ny][nx] == '#') continue;
          if (dist[ny][nx] != -1) continue;
          q.push(make_pair(ny, nx));
          dist[ny][nx] = dist[y][x] + 1;
          mx = max(dist[ny][nx], mx);
        }
      }
    }
    ans = max(ans, mx);
  }
  cout << ans << endl;
}
