#include <bits/stdc++.h>
using namespace std;
long long k = 0;
void solve() {
  long long n, m;
  cin >> n >> m;
  vector<vector<long long>> graph(n * m);
  vector<string> ss;
  for (long long i = 0; i < n; i++) {
    string s;
    cin >> s;
    ss.push_back(s);
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (ss[i][j] == '.') {
        if (i + 1 < n and ss[i + 1][j] == '.') {
          graph[i * m + j].push_back((i + 1) * m + j);
        }
        if (j + 1 < m and ss[i][j + 1] == '.') {
          graph[i * m + j].push_back(i * m + (j + 1));
        }
        if (i - 1 >= 0 and ss[i - 1][j] == '.') {
          graph[i * m + j].push_back((i - 1) * m + j);
        }
        if (j - 1 >= 0 and ss[i][j - 1] == '.') {
          graph[i * m + j].push_back(i * m + (j - 1));
        }
      }
    }
  }
  long long ans = 0;
  for (long long i = 0; i < n * m; i++) {
    k = 0;
    vector<long long> level(n * m, 0);
    queue<long long> q;
    q.push(i);
    level[i] = 0;
    if (ss[i / m][i % m] == '#') continue;
    while (!q.empty()) {
      long long node = q.front();
      q.pop();
      for (auto x : graph[node]) {
        if (!level[x]) {
          level[x] = level[node] + 1;
          k = max(k, level[x]);
          q.push(x);
        }
      }
    }
    ans = max(ans, k);
  }
  cout << ans;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  while (t--) solve();
  return 0;
}
