#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int dx[] = {-1, 1, 0, 0}, dy[] = {0, 0, 1, -1};
const int MAX_N = 27;
int H, W;
string g[MAX_N];
map<pair<int, int>, int> dist;
int bfs(int a, int b, int c, int d) {
  dist.clear();
  queue<pair<int, int>> que;
  dist[make_pair(a, b)] = 0;
  que.emplace(a, b);
  while (!que.empty()) {
    auto cur = que.front();
    que.pop();
    if (cur.first == c && cur.second == d) {
      return dist[cur];
    }
    for (int i = 0; i < 4; ++i) {
      int nx = cur.first + dx[i];
      int ny = cur.second + dy[i];
      if (nx >= 0 && nx < H && ny >= 0 && ny < W && g[nx][nx] != '#') {
        if (!dist.count(make_pair(nx, ny))) {
          que.emplace(nx, ny);
          dist[make_pair(nx, ny)] = dist[cur] + 1;
        }
      }
    }
  }
  return -1;
}
void solve() {
  int ans = 0;
  for (int i = 0; i < H; ++i)
    for (int j = 0; j < W; ++j)
      if (g[i][j] == '.') {
        for (int x = 0; x < H; ++x)
          for (int y = 0; y < W; ++y)
            if (g[x][y] == '.') {
              if (i != x || j != y) ans = max(ans, bfs(i, j, x, y));
            }
      }
  cout << ans << '\n';
}
int main() {
  cin >> H >> W;
  for (int i = 0; i < H; ++i) cin >> g[i];
  solve();
  return 0;
}
