#include <bits/stdc++.h>
using namespace std;
long long int dis[200008];
std::vector<std::vector<long long int>> adj(200008);
bool BFS(long long int src, long long int dest, long long int v,
         long long int pred[], long long int dist[]) {
  list<long long int> queue;
  bool visited[v];
  for (long long int i = 0; i < v; i++) {
    visited[i] = false;
    dist[i] = INT_MAX;
    pred[i] = -1;
  }
  visited[src] = true;
  dist[src] = 0;
  queue.push_back(src);
  while (!queue.empty()) {
    long long int u = queue.front();
    queue.pop_front();
    for (long long int i = 0; i < adj[u].size(); i++) {
      if (visited[adj[u][i]] == false) {
        visited[adj[u][i]] = true;
        dist[adj[u][i]] = dist[u] + 1;
        pred[adj[u][i]] = u;
        queue.push_back(adj[u][i]);
        if (adj[u][i] == dest) return true;
      }
    }
  }
  return false;
}
long long int printShortestDistance(long long int s, long long int dest,
                                    long long int v) {
  long long int pred[v], dist[v];
  if (BFS(s, dest, v, pred, dist) == false) {
    return 1000000;
  }
  vector<long long int> path;
  long long int crawl = dest;
  path.push_back(crawl);
  while (pred[crawl] != -1) {
    path.push_back(pred[crawl]);
    crawl = pred[crawl];
  }
  return dist[dest];
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long int n, m, i, j;
  cin >> n >> m;
  string arr[n];
  std::vector<long long int> v;
  for (i = 0; i < n; i++) cin >> arr[i];
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      long long int k = i * m + j;
      if (arr[i][j] == '#') continue;
      if (arr[i][j] == '.') v.push_back(k);
      if (j + 1 < m && arr[i][j] == '.' && arr[i][j + 1] == '.') {
        adj[k].push_back(k + 1);
        adj[k + 1].push_back(k);
      }
      if (i + 1 < n && arr[i][j] == '.' && arr[i + 1][j] == '.') {
        adj[k].push_back(k + m);
        adj[k + m].push_back(k);
      }
    }
  }
  long long int ans = -1;
  for (i = 0; i < v.size(); i++) {
    for (j = 0; j < v.size(); j++) {
      if (v[i] == v[j]) continue;
      ans = max(ans, printShortestDistance(v[i], v[j], 10000));
    }
  }
  cout << ans << endl;
}
