#include <bits/stdc++.h>
using namespace std;
const long long int infinity = 9e18;
int n, m;
int ans(vector<bool> &visited, vector<vector<int>> &vp, int i, int &node) {
  queue<int> q;
  q.push(i);
  visited[i] = 1;
  vector<int> dist(n * m, INT_MAX);
  dist[i] = 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 maxi = 0;
  for (int j = 0; j < n * m; j++) {
    if (dist[j] != INT_MAX) {
      if (maxi < dist[j]) {
        maxi = dist[j];
        node = j;
      }
    }
  }
  return maxi;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  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] == '.') {
      int node = 0;
      int x = ans(visited, vp, i, node);
      vector<bool> vis(n * m, 0);
      int y = 0;
      x = ans(vis, vp, node, y);
      maxim = max(maxim, x);
    }
  }
  cout << maxim;
  return 0;
}
