#include <bits/stdc++.h>
using namespace std;
const int inf = 1001001001;
const int mod = 1000000007;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w;
  cin >> h >> w;
  char mp[21][21];
  for (int i = 0; i < (h); ++i)
    for (int j = 0; j < (w); ++j) cin >> mp[i][j];
  int ans[21][21];
  constexpr int dx[] = {-1, 0, 1, 0};
  constexpr int dy[] = {0, 1, 0, -1};
  auto bfs = [&](int sx, int sy) {
    queue<pair<int, int> > que;
    que.push(pair<int, int>(sx, sy));
    ans[sx][sy] = 0;
    while (!que.empty()) {
      pair<int, int> p = que.front();
      que.pop();
      for (int i = 0; i < (4); ++i) {
        int nx = p.first + dx[i], ny = p.second + dy[i];
        if (nx < 0 || ny < 0 || nx >= h || ny >= w) continue;
        if (ans[nx][ny] != inf) continue;
        if (mp[nx][ny] == '#') continue;
        ans[nx][ny] = ans[p.first][p.second] + 1;
        que.push(pair<int, int>(nx, ny));
      }
    }
    return;
  };
  int j_ans = 0;
  for (int i = 0; i < (h); ++i)
    for (int j = 0; j < (w); ++j) {
      for (int k = 0; k < (h); ++k)
        for (int l = 0; l < (w); ++l) ans[k][l] = inf;
      bfs(i, j);
      for (int k = 0; k < (h); ++k)
        for (int l = 0; l < (w); ++l)
          if (mp[k][l] != '#') j_ans = max(j_ans, ans[k][l]);
    }
  cout << (j_ans) << "\n";
  return 0;
}
