#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long inf = 1e9 + 5;
const long long nax = 2e5 + 5;
void min_self(long long& a, long long b) { a = min(a, b); }
void max_self(long long& a, long long b) { a = max(a, b); }
void add_self(long long& a, long long b) { a = (a + b) % mod; }
queue<pair<long long, long long>> q;
void bfs(vector<string>& arr, vector<vector<long long>>& dp, long long i,
         long long j, vector<vector<bool>>& visited) {
  long long h = arr.size(), w = arr[0].size();
  if (i < 0 || j >= w || i >= h || j < 0 || arr[i][j] == '#' || visited[i][j])
    return;
  visited[i][j] = true;
  if (i - 1 >= 0) {
    min_self(dp[i - 1][j], dp[i][j] + 1);
  }
  if (j - 1 >= 0) {
    min_self(dp[i][j - 1], dp[i][j] + 1);
  }
  if (i + 1 < h) {
    min_self(dp[i + 1][j], dp[i][j] + 1);
  }
  if (j + 1 < w) {
    min_self(dp[i][j + 1], dp[i][j] + 1);
  }
  q.push({i - 1, j});
  q.push({i, j - 1});
  q.push({i + 1, j});
  q.push({i, j + 1});
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long h, w;
  cin >> h >> w;
  vector<string> arr(h);
  for (long long i = 0; i < h; i++) {
    cin >> arr[i];
  }
  long long ans = 0;
  for (long long si = 0; si < h; si++) {
    for (long long sj = 0; sj < w; sj++) {
      vector<vector<bool>> visited(25, vector<bool>(25));
      if (arr[si][sj] == '#') continue;
      vector<vector<long long>> dp(h, vector<long long>(w, inf));
      dp[si][sj] = 0;
      q.push({si, sj});
      while (!q.empty()) {
        pair<long long, long long> node = q.front();
        q.pop();
        bfs(arr, dp, node.first, node.second, visited);
      }
      for (long long ei = 0; ei < h; ei++) {
        for (long long ej = 0; ej < w; ej++) {
          max_self(ans, dp[ei][ej]);
        }
      }
    }
  }
  cout << ans;
}
