#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long double EPS = 1e-6;
const int N = 21;
char grid[N][N];
int dist[N][N][N][N];
int tmp[N][N];
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
int n, m;
inline bool valid(int x, int y) {
  return x <= n and 1 <= x and y <= m and 1 <= y and grid[x][y] == '.';
}
int BFS(int x, int y, int tx, int ty) {
  queue<pair<int, int> > q;
  q.push(make_pair(x, y));
  while (!q.empty()) {
    auto u = q.front();
    q.pop();
    int c = tmp[u.first][u.second];
    for (int(i) = 0; (i) < (int)4; (i)++) {
      int nx = u.first + dx[i], ny = u.second + dy[i];
      if (valid(nx, ny) && !tmp[nx][ny]) {
        tmp[nx][ny] = c + 1;
        if (nx == tx and ny == ty) goto OVER;
        q.push(make_pair(nx, ny));
      }
    }
  }
OVER:
  dist[x][y][tx][ty] = tmp[tx][ty];
  dist[tx][ty][x][y] = tmp[tx][ty];
  return tmp[tx][ty];
}
int main() {
  cin >> n >> m;
  for (int(i) = 1; (i) <= (int)n; (i)++) scanf("%s", grid[i] + 1);
  int ans = 0;
  for (int(x1) = 1; (x1) <= (int)n; (x1)++)
    for (int(y1) = 1; (y1) <= (int)m; (y1)++)
      for (int(x2) = 1; (x2) <= (int)n; (x2)++)
        for (int(y2) = 1; (y2) <= (int)m; (y2)++) {
          if (dist[x1][y1][x2][y2]) continue;
          memset(tmp, 0, sizeof(tmp));
          ans = max(ans, BFS(x1, y1, x2, y2));
        }
  cout << ans << endl;
  return 0;
}
