#include <bits/stdc++.h>
using namespace std;
const long long logN = 20;
const long long M = 1000000007;
const long long INF = 1e12;
const long long N = 25;
string s[N];
long long dp[N][N];
long long ans;
long long dx[4] = {0, 0, 1, -1};
long long dy[4] = {1, -1, 0, 0};
long long h, w;
bool check(long long x, long long y) {
  return x >= 0 and y >= 0 and x < h and y < w;
}
void bfs(long long x, long long y) {
  for (long long i = 0; i < N; i++)
    for (long long j = 0; j < N; j++) dp[i][j] = M;
  queue<pair<long long, long long> > q;
  q.push({x, y});
  dp[x][y] = 0;
  while (!q.empty()) {
    pair<long long, long long> p = q.front();
    q.pop();
    long long xx = p.first, yy = p.second;
    for (long long i = 0; i < 4; i++) {
      if (check(xx + dx[i], yy + dy[i]) and s[xx + dx[i]][yy + dy[i]] != '#' and
          dp[xx + dx[i]][yy + dy[i]] > dp[xx][yy]) {
        dp[xx + dx[i]][yy + dy[i]] = dp[xx][yy] + 1;
        q.push({xx + dx[i], yy + dy[i]});
      }
    }
  }
  for (long long i = 0; i < h; i++)
    for (long long j = 0; j < w; j++) {
      if (s[i][j] != '#') ans = max(ans, dp[i][j]);
    }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> h >> w;
  for (long long i = 0; i < h; i++) cin >> s[i];
  for (long long i = 0; i < h; i++)
    for (long long j = 0; j < w; j++) {
      if (s[i][j] != '#') bfs(i, j);
    }
  cout << ans << "\n";
  return 0;
}
