#include <bits/stdc++.h>
using namespace std;
const int maxn = 24;
template <typename T>
T read() {
  T x = 0;
  int w = 1;
  char ch = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + (ch - '0');
    ch = getchar();
  }
  return x * w;
}
template <typename T>
inline void write(T x) {
  static int sta[35];
  int top = 0;
  do {
    sta[top++] = x % 10, x /= 10;
  } while (x);
  while (top) putchar(sta[--top] + 48);
  puts("");
}
int n, m;
char mp[maxn][maxn];
bool vis[maxn][maxn];
int dir[4][2] = {1, 0, -1, 0, 0, 1, 0, -1};
int ans;
struct node {
  int x, y, c;
};
void bfs(int x, int y) {
  vis[x][y] = 1;
  memset(vis, 0, sizeof(vis));
  queue<node> q;
  q.push({x, y, 0});
  while (!q.empty()) {
    node now = q.front();
    ans = max(ans, now.c);
    q.pop();
    for (int i = 0; i < 4; ++i) {
      node tmp;
      tmp.x = now.x + dir[i][0];
      tmp.y = now.y + dir[i][1];
      tmp.c = now.c + 1;
      if (tmp.x < 1 || tmp.x > n || tmp.y < 1 || tmp.y > m ||
          vis[tmp.x][tmp.y] || mp[tmp.x][tmp.y] == '#')
        continue;
      vis[tmp.x][tmp.y] = 1;
      q.push(tmp);
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) scanf(" %c", &mp[i][j]);
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      if (mp[i][j] == '.') bfs(i, j);
    }
  }
  cout << ans << endl;
  return 0;
}
