#include <bits/stdc++.h>
using namespace std;
const int N = 20 + 5;
const int M = 20 + 5;
const int INF = 1162167621;
int dx[] = {0, 0, -1, 1};
int dy[] = {-1, 1, 0, 0};
char g[N][M];
int n, m, dist[N][M];
bool ok(pair<int, int> u) {
  if (u.first < n and u.second < m and g[u.first][u.second] == '.') return true;
  return false;
}
void dijkstra(int i, int j) {
  memset(dist, 69, sizeof dist);
  dist[i][j] = 0;
  priority_queue<pair<int, pair<int, int>>> q;
  q.emplace(dist[i][j], make_pair(i, j));
  while (!q.empty()) {
    auto u = q.top().second;
    q.pop();
    for (int i = 0; i < 4; i++) {
      auto v = make_pair(u.first + dx[i], u.second + dy[i]);
      if (ok(v) and dist[v.first][v.second] > dist[u.first][u.second] + 1) {
        dist[v.first][v.second] = dist[u.first][u.second] + 1;
        q.emplace(dist[v.first][v.second], v);
      }
    }
  }
}
int find_max() {
  int mx = -1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (dist[i][j] == INF) continue;
      mx = max(mx, dist[i][j]);
    }
  }
  return mx;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> g[i][j];
    }
  }
  int cnt = -1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      dijkstra(i, j);
      cnt = max(cnt, find_max());
    }
  }
  cout << cnt << '\n';
}
