#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
char s[25][25];
int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
int n, m, ex, ey;
int d[25][25];
void bfs(int x, int y) {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      d[i][j] = INF;
    }
  }
  d[x][y] = 0;
  queue<pair<int, int> > qu;
  qu.push({x, y});
  while (!qu.empty()) {
    pair<int, int> u = qu.front();
    qu.pop();
    for (int i = 0; i < 4; i++) {
      int xx = dx[i] + u.first, yy = dy[i] + u.second;
      if (xx < 0 || xx >= n || yy < 0 || yy >= m || s[xx][yy] == '#') continue;
      if (d[xx][yy] > d[u.first][u.second] + 1) {
        d[xx][yy] = d[u.first][u.second] + 1;
        qu.push({xx, yy});
      }
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%s", s[i]);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      bfs(i, j);
      for (int k = 0; k < n; k++) {
        for (int l = 0; l < m; l++) {
          if (d[k][l] != INF) ans = max(ans, d[k][l]);
        }
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
