#include <bits/stdc++.h>
using namespace std;
int n, m, ans = 0;
int dx[5] = {0, 1, 0, -1, 0}, dy[5] = {0, 0, 1, 0, -1};
char a[30][30];
int dis[30][30][30][30] = {};
bool vis[30][30][30][30] = {};
queue<pair<int, int> > q;
void bfs(int x, int y) {
  q.push(make_pair(x, y));
  dis[x][y][x][y] = 0;
  vis[x][y][x][y] = true;
  while (!q.empty()) {
    pair<int, int> t = q.front();
    for (int i = 1; i <= 4; i++) {
      int tx = t.first + dx[i], ty = t.second + dy[i];
      if (!vis[x][y][tx][ty] && a[tx][ty] == '.') {
        q.push(make_pair(tx, ty));
        dis[x][y][tx][ty] = dis[x][y][t.first][t.second] + 1;
        vis[x][y][tx][ty] = true;
      }
    }
    q.pop();
  }
  return;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) a[i][0] = a[i][m + 1] = '#';
  for (int j = 1; j <= m; j++) a[0][j] = a[n + 1][j] = '#';
  for (int i = 1; i <= n; i++) scanf("%s", &a[i][1]);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (a[i][j] == '.') bfs(i, j);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      for (int k = 1; k <= n; k++)
        for (int l = 1; l <= m; l++)
          if (vis[i][j][k][l]) ans = max(ans, dis[i][j][k][l]);
  printf("%d", ans);
  return 0;
}
