#include <bits/stdc++.h>
using namespace std;
int H, W, ans;
char S[25][25];
int bfs(int sy, int sx) {
  queue<pair<int, int> > q;
  q.push({sy, sx});
  int y, x, dpp, d[25][25] = {{0}};
  while (!q.empty()) {
    pair<int, int> p = q.front();
    q.pop();
    y = p.first, x = p.second, dpp = d[y][x] + 1;
    if (d[y + 1][x] == 0 && S[y + 1][x] == '.')
      q.push({y + 1, x}), d[y + 1][x] = dpp;
    if (d[y - 1][x] == 0 && S[y - 1][x] == '.')
      q.push({y - 1, x}), d[y - 1][x] = dpp;
    if (d[y][x + 1] == 0 && S[y][x + 1] == '.')
      q.push({y, x + 1}), d[y][x + 1] = dpp;
    if (d[y][x - 1] == 0 && S[y][x - 1] == '.')
      q.push({y, x - 1}), d[y][x - 1] = dpp;
  }
  return d[y][x];
}
int main() {
  scanf("%d %d\n", &H, &W);
  for (int i = 1; i <= H; ++i) scanf("%s\n", &S[i][1]);
  for (int y = 1; y <= H; ++y) {
    for (int x = 1; x <= W; ++x) {
      if (S[y][x] == '#') continue;
      ans = max(bfs(y, x), ans);
    }
  }
  printf("%d\n", ans);
}
