#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int n, m;
char c[25][25];
int vis[25][25];
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
queue<pair<int, int> > Q;
int dis[25][25];
int Ans = 0;
void bfs(int xw, int yw) {
  memset(vis, 0, sizeof(vis));
  memset(dis, -1, sizeof(dis));
  while (!Q.empty()) Q.pop();
  Q.push(pair<int, int>(xw, yw));
  dis[xw][yw] = 0;
  while (!Q.empty()) {
    pair<int, int> t = Q.front();
    Q.pop();
    int ry = t.first, cy = t.second;
    for (int i = 0; i < 4; i++) {
      int rr = ry + dx[i];
      int cc = cy + dy[i];
      if (rr < 1 || cc < 1 || rr > n || cc > m) continue;
      if (c[rr][cc] == '#' || vis[rr][cc] == 1) continue;
      vis[rr][cc] = 1;
      dis[rr][cc] = dis[ry][cy] + 1;
      Ans = max(Ans, dis[rr][cc]);
      Q.push(pair<int, int>(rr, cc));
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) scanf("%s", c[i] + 1);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      bfs(i, j);
    }
  }
  printf("%d\n", Ans);
  return 0;
}
