#include <bits/stdc++.h>
using namespace std;
vector<std::vector<int>> adj;
char a[30][30];
int ans[100500];
int n, m, an = 0;
int f(int x, int y) { return (x - 1) * m + y; }
std::pair<int, int> rf(int x) { return {(x + m - 1) / m, x % m}; }
void d(int start) {
  for (int i = 1; i <= n * m; i++) ans[i] = INT_MAX;
  ans[start] = 0;
  priority_queue<std::pair<int, int>, vector<std::pair<int, int>>,
                 greater<std::pair<int, int>>>
      q;
  q.push({0, start});
  while (!q.empty()) {
    std::pair<int, int> c = q.top();
    q.pop();
    int dst = c.first, v = c.second;
    if (ans[v] < dst) continue;
    for (int i : adj[v]) {
      int u = i;
      int n_dst = dst + 1;
      if (n_dst < ans[u]) {
        ans[u] = n_dst;
        q.push({n_dst, u});
      }
    }
  }
  for (int i = 1; i <= n * m; i++) {
    if (i == start || a[rf(i).first][rf(i).second] == '#') continue;
    an = max(an, ans[i]);
  }
}
void solve() {
  cin >> n >> m;
  adj = vector<std::vector<int>>(n * m + 1);
  for (int i = 0; i <= n + 1; i++) {
    for (int j = 0; j <= m + 1; j++) {
      a[i][j] = '#';
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) cin >> a[i][j];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (a[i][j] == '#') continue;
      if (a[i + 1][j] == '.') {
        adj[f(i, j)].push_back(f(i + 1, j));
        adj[f(i + 1, j)].push_back(f(i, j));
      }
      if (a[i - 1][j] == '.') {
        adj[f(i, j)].push_back(f(i - 1, j));
        adj[f(i - 1, j)].push_back(f(i, j));
      }
      if (a[i][j + 1] == '.') {
        adj[f(i, j)].push_back(f(i, j + 1));
        adj[f(i, j + 1)].push_back(f(i, j));
      }
      if (a[i][j - 1] == '.') {
        adj[f(i, j)].push_back(f(i, j - 1));
        adj[f(i, j - 1)].push_back(f(i, j));
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (a[i][j] == '.') d(f(i, j));
    }
  }
  if (an == INT_MAX)
    cout << 0;
  else
    cout << an;
}
int main() {
  ios::sync_with_stdio(false);
  int q = 1;
  for (int i = 1; i <= q; i++) {
    solve();
  }
}
