#include <bits/stdc++.h>
using namespace std;
long long int pass[200008];
long long int fail[200008];
long long int dis[200008];
std::vector<std::vector<long long int>> adj(200008);
pair<long long int, long long int> bfs(long long int u) {
  memset(dis, -1, sizeof(dis));
  queue<long long int> q;
  q.push(u);
  dis[u] = 0;
  while (!q.empty()) {
    long long int t = q.front();
    q.pop();
    for (auto it = adj[t].begin(); it != adj[t].end(); it++) {
      long long int v = *it;
      if (dis[v] == -1) {
        q.push(v);
        dis[v] = dis[t] + 1;
      }
    }
  }
  long long int maxDis = 0;
  long long int nodeIdx;
  for (long long int i = 0; i < 200008; i++) {
    if (dis[i] > maxDis) {
      maxDis = dis[i];
      nodeIdx = i;
    }
  }
  return make_pair(nodeIdx, maxDis);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long int n, m, i, j;
  cin >> n >> m;
  string arr[n];
  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 (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);
      }
    }
  }
  pair<long long int, long long int> p = bfs(0);
  pair<long long int, long long int> p1 = bfs(p.first);
  cout << p1.second << endl;
}
