#include <bits/stdc++.h>
using namespace std;
int dfs(int i, int j, vector<string>& v, vector<vector<bool>> vis) {
  int maxi = 0;
  queue<pair<pair<int, int>, int>> q;
  q.push({{i, j}, 0});
  while (!q.empty()) {
    pair<int, int> t = q.front().first;
    vis[t.first][t.second] = true;
    int num = q.front().second;
    q.pop();
    if (t.first >= 1 && v[t.first - 1][t.second] == '.' &&
        !vis[t.first - 1][t.second])
      q.push({{t.first - 1, t.second}, num + 1});
    if (t.second >= 1 && v[t.first][t.second - 1] == '.' &&
        !vis[t.first][t.second - 1])
      q.push({{t.first, t.second - 1}, num + 1});
    if (t.first + 1 < (int)v.size() && v[t.first + 1][t.second] == '.' &&
        !vis[t.first + 1][t.second])
      q.push({{t.first + 1, t.second}, num + 1});
    if (t.second + 1 < (int)v[0].size() && v[t.first][t.second + 1] == '.' &&
        !vis[t.first][t.second + 1])
      q.push({{t.first, t.second + 1}, num + 1});
    maxi = max(q.back().second, maxi);
  }
  return maxi;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<string> v(n + 1);
  vector<vector<bool>> vis(n + 1, vector<bool>(m, false));
  for (auto& p : v) cin >> p;
  int maxi = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (v[i][j] == '.') {
        maxi = max(maxi, dfs(i, j, v, vis));
      }
    }
  }
  cout << maxi << '\n';
  return 0;
}
