#include <bits/stdc++.h>
using namespace std;
const int Maxn = 30, inf = 0x3f3f3f3f;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, -1, 1};
bool a[Maxn][Maxn], vis[Maxn][Maxn];
int dis[Maxn][Maxn];
int n, m, ans;
struct node {
  int x, y;
  node(int u, int v) { x = u, y = v; }
};
inline bool check(int x, int y) {
  return (x < 1 || y < 1 || x > n || y > m || a[x][y] || vis[x][y]);
}
void bfs(int sx, int sy) {
  memset(dis, 0, sizeof(dis));
  memset(vis, 0, sizeof(vis));
  queue<node> q;
  vis[sx][sy] = 1, q.push(node(sx, sy));
  while (q.size()) {
    int x = q.front().x, y = q.front().y;
    q.pop();
    ans = max(ans, dis[x][y]);
    for (int i = 0; i < 4; ++i) {
      int u = x + dx[i], v = y + dy[i];
      if (check(u, v)) continue;
      vis[u][v] = 1, q.push(node(u, v));
      dis[u][v] = dis[x][y] + 1;
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    char tmp[Maxn];
    scanf("%s", tmp + 1);
    for (int j = 1; j <= m; ++j)
      if (tmp[j] == '#') a[i][j] = 1;
  }
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) bfs(i, j);
  printf("%d\n", ans);
  return 0;
}
