#include <bits/stdc++.h>
using namespace std;
int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 3) + (x << 1) + c - 48;
    c = getchar();
  }
  return x * f;
}
int k, m, n;
char c[100][100];
int a[100][100];
int ans = 0;
int vis[100][100], dis[100][100];
queue<pair<int, int> > q;
inline void bfs(int x, int y) {
  memset(vis, 0, sizeof(vis));
  memset(dis, 0, sizeof(dis));
  q.push(make_pair(x, y));
  vis[x][y] = 1;
  while (!q.empty()) {
    int x = q.front().first, y = q.front().second;
    q.pop();
    ans = max(ans, dis[x][y]);
    if (a[x + 1][y] && !vis[x + 1][y]) {
      dis[x + 1][y] = dis[x][y] + 1;
      vis[x + 1][y] = 1;
      q.push(make_pair(x + 1, y));
    }
    if (a[x - 1][y] && !vis[x - 1][y]) {
      dis[x - 1][y] = dis[x][y] + 1;
      vis[x - 1][y] = 1;
      q.push(make_pair(x - 1, y));
    }
    if (a[x][y + 1] && !vis[x][y + 1]) {
      dis[x][y + 1] = dis[x][y] + 1;
      vis[x][y + 1] = 1;
      q.push(make_pair(x, y + 1));
    }
    if (a[x][y - 1] && !vis[x][y - 1]) {
      dis[x][y - 1] = dis[x][y] + 1;
      vis[x][y - 1] = 1;
      q.push(make_pair(x, y - 1));
    }
  }
  return;
}
int main() {
  n = read();
  m = read();
  for (register int i = 1; i <= n; i++) {
    scanf("%s", c[i] + 1);
    for (register int j = 1; j <= m; j++) {
      if (c[i][j] == '.') a[i][j] = 1;
    }
  }
  for (register int i = 1; i <= n; i++) {
    for (register int j = 1; j <= m; j++) {
      bfs(i, j);
    }
  }
  printf("%d\n", ans);
  return 0;
}
