#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
int n, m;
string g[21];
bool vis[21][21];
bool valid(int x, int y) {
  return 0 <= x && x < n && 0 <= y && y < m && !vis[x][y] && g[x][y] == '.';
}
int bfs(int x, int y) {
  int ans = 0;
  queue<pair<pair<int, int>, int>> q;
  q.push({{x, y}, 0});
  while (!q.empty()) {
    pair<int, int> atual = q.front().first;
    vis[atual.first][atual.second] = true;
    int d = q.front().second;
    q.pop();
    if (valid(atual.first + 1, atual.second))
      q.push({{atual.first + 1, atual.second}, d + 1});
    if (valid(atual.first - 1, atual.second))
      q.push({{atual.first - 1, atual.second}, d + 1});
    if (valid(atual.first, atual.second + 1))
      q.push({{atual.first, atual.second + 1}, d + 1});
    if (valid(atual.first, atual.second - 1))
      q.push({{atual.first, atual.second - 1}, d + 1});
    ans = max(ans, d);
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < (int)n; i++) cin >> g[i];
  int ans = 0;
  for (int i = 0; i < (int)n; i++) {
    for (int j = 0; j < (int)m; j++) {
      if (g[i][j] == '.') {
        memset(vis, false, sizeof(vis));
        ans = max(ans, bfs(i, j));
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
