#include <bits/stdc++.h>
using namespace std;
int n, m;
char G[30][30];
int dist[30][30];
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int solve(pair<int, int> s, pair<int, int> e) {
  queue<pair<int, int> > q;
  memset(dist, -1, sizeof(dist));
  dist[s.first][s.second] = 0;
  q.push(s);
  while (!q.empty()) {
    pair<int, int> c = q.front();
    q.pop();
    for (int i = 0; i < 4; i++) {
      int x = c.first + dx[i], y = c.second + dy[i];
      if (x >= 0 and x < n and y >= 0 and y < m and dist[x][y] == -1 and
          G[x][y] != '#') {
        dist[x][y] = dist[c.first][c.second] + 1;
        q.push({x, y});
      }
    }
  }
  return dist[e.first][e.second];
}
int32_t main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> G[i][j];
  int ans = -1;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      for (int a = 0; a < n; a++)
        for (int b = 0; b < m; b++) ans = max(ans, solve({i, j}, {a, b}));
  cout << ans << '\n';
  return 0;
}
