#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long H, W;
  cin >> H >> W;
  string S[H];
  for (int i = 0; i < H; i++) {
    cin >> S[i];
  }
  vector<vector<long long>> mp(H + 1, vector<long long>(W + 1));
  for (int i = 0; i <= H; i++) {
    for (int j = 0; j <= W; j++) {
      if (i == 0 || j == 0) {
        mp[i][j] = 1;
      } else {
        if (S[i - 1][j - 1] == '#') mp[i][j] == 1;
      }
    }
  }
  long long m = 0, x, y, dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, ans = 0;
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      if (mp[i][j] != 0) continue;
      long long dist[25][25] = {};
      queue<pair<long long, long long>> qu;
      qu.push(pair<long long, long long>{i, j});
      dist[i][j] = 1;
      while (!qu.empty()) {
        tie(x, y) = qu.front();
        qu.pop();
        for (int k = 0; k < 4; k++) {
          int nx = x + dx[i], ny = y + dy[i];
          if (dist[nx][ny] != 0 || mp[nx][ny] != 0) continue;
          dist[nx][ny] = dist[x][y] + 1;
          m = max(m, dist[nx][ny]);
          qu.push(pair<long long, long long>{nx, ny});
        }
      }
      ans = max(ans, m);
    }
  }
  cout << ans << "\n";
  return 0;
}
