#include <bits/stdc++.h>
using namespace std;
const long long int infinity = 9e18;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<string> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  vector<vector<int>> vp(n * m);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (v[i][j] == '.') {
        if (i < (n - 1) && v[i + 1][j] == '.') {
          vp[i * m + j].push_back((i + 1) * m + j);
          vp[(i + 1) * m + j].push_back(i * m + j);
        }
        if (j < (m - 1) && v[i][j + 1] == '.') {
          vp[i * m + j].push_back(i * m + j + 1);
          vp[i * m + j + 1].push_back(i * m + j);
        }
      }
    }
  }
  vector<bool> visited(n * m, 0);
  int maxim = 0;
  for (int i = 0; i < n * m; i++) {
    if (!visited[i] && v[i / m][i % m] == '.') {
      queue<int> q;
      q.push(i);
      visited[i] = 1;
      vector<int> dist(n * m, INT_MAX);
      dist[0] = 0;
      while (!q.empty()) {
        int p = q.front();
        q.pop();
        for (auto j : vp[p]) {
          if (!visited[j]) {
            visited[j] = 1;
            dist[j] = dist[p] + 1;
            q.push(j);
          }
        }
      }
      int idx = 0;
      int maxi = 0;
      for (int j = 0; j < n * m; j++) {
        if (dist[j] != INT_MAX) {
          if (maxi < dist[j]) {
            maxi = dist[j];
            idx = j;
          }
        }
      }
      vector<bool> vis(n * m, 0);
      dist.assign(n * m, INT_MAX);
      dist[idx] = 0;
      q.push(idx);
      while (!q.empty()) {
        int p = q.front();
        q.pop();
        for (auto j : vp[p]) {
          if (!vis[j]) {
            vis[j] = 1;
            dist[j] = dist[p] + 1;
            q.push(j);
          }
        }
      }
      maxi = 0;
      for (int j = 0; j < n * m; j++) {
        if (dist[j] != INT_MAX) {
          if (maxi < dist[j]) {
            maxi = dist[j];
          }
        }
      }
      maxim = max(maxim, maxi);
    }
  }
  cout << maxim;
  return 0;
}
