#include <bits/stdc++.h>
using namespace std;
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr long long MOD = 1000000007;
using Graph = vector<vector<long long>>;
const long long dx[4] = {1, 0, -1, 0};
const long long dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  long long H, W;
  cin >> H >> W;
  string S[H];
  for (long long i = 0; i < (long long)(H); i++) {
    cin >> S[i];
  }
  long long ans = -1;
  for (long long i = 0; i < (long long)(H); i++) {
    for (long long j = 0; j < (long long)(W); j++) {
      vector<vector<long long>> dist(H, vector<long long>(W, -1));
      queue<pair<long long, long long>> que;
      dist[i][j] = 0;
      que.push(make_pair(i, j));
      while (!que.empty()) {
        pair<long long, long long> nv = que.front();
        que.pop();
        long long x = nv.first;
        long long y = nv.second;
        for (long long k = 0; k < (long long)(4); k++) {
          long long nx = x + dx[k];
          long long ny = y + dy[k];
          if (nx < 0 || ny < 0 || nx >= H || ny >= W) continue;
          if (S[nx][ny] == '#') continue;
          if (dist[nx][ny] == -1) {
            que.push(make_pair(nx, ny));
            dist[nx][ny] = dist[x][y] + 1;
          }
        }
      }
      for (long long k = 0; k < (long long)(H); k++) {
        for (long long l = 0; l < (long long)(W); l++) {
          ans = max(ans, dist[k][l]);
        }
      }
    }
  }
  cout << ans << endl;
}
