#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18 + 7;
const long long N = 1e6 + 7;
const long long md = 1e9 + 7;
long long dist[30], vis[30];
char a[30][30];
long long n, m;
long long val[30][30];
std::vector<long long> g[30];
long long ok(long long i, long long j) {
  if ((i >= 0 && i < n) && (j >= 0 && j < m)) {
    if (a[i][j] == '.') return 1;
  }
  return 0;
}
void bfs(long long src) {
  std::queue<long long> q;
  long long from;
  q.push(src);
  vis[src] = 1;
  dist[src] = 0;
  while (!q.empty()) {
    from = q.front();
    q.pop();
    for (auto &to : g[from]) {
      if (vis[to]) continue;
      q.push(to);
      vis[to] = 1;
      dist[to] = dist[from] + 1;
    }
  }
}
void sol() {
  long long nodes = 0;
  long long ans = 0;
  cin >> n >> m;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (a[i][j] == '.') {
        val[i][j] = nodes++;
      }
    }
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (a[i][j] == '.') {
        if (ok(i + 1, j)) {
          g[val[i][j]].push_back(val[i + 1][j]);
        }
        if (ok(i, j - 1)) {
          g[val[i][j]].push_back(val[i][j - 1]);
        }
        if (ok(i - 1, j)) {
          g[val[i][j]].push_back(val[i - 1][j]);
        }
        if (ok(i, j + 1)) {
          g[val[i][j]].push_back(val[i][j + 1]);
        }
      }
    }
  }
  for (long long i = 0; i < nodes; i++) {
    memset(dist, 0, sizeof(dist));
    memset(vis, 0, sizeof(vis));
    bfs(i);
    for (long long j = 0; j < nodes; j++) {
      ans = max(ans, dist[j]);
    }
  }
  cout << ans << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long T = 1;
  sol();
  return 0;
}
