#include <bits/stdc++.h>
using namespace std;
char s[25][25];
int bfs(int one, int two) {
  int d[25][25];
  for (int o = 0; o < 25; o++)
    for (int i = 0; i < 25; i++) d[o][i] = -1;
  d[one][two] = 0;
  queue<pair<int, int>> q;
  q.push({one, two});
  int z[4][2] = {{1, 0}, {-1, 0}, {0, -1}, {0, 1}};
  int res = 0;
  while (!q.empty()) {
    int a, b;
    tie(a, b) = q.front();
    q.pop();
    for (int j = 0; j < 4; j++) {
      int e = a + z[j][0];
      int f = b + z[j][1];
      if (d[e][f] != -1 || s[e][f] != '.') continue;
      d[e][f] = d[a][b] + 1;
      q.push({e, f});
      res = max(res, d[e][f]);
    }
  }
  return res;
}
int main() {
  int h, w;
  scanf("%d%d", &h, &w);
  for (int o = 0; o <= h + 1; o++)
    for (int i = 0; i <= w + 1; i++) s[o][i] = '#';
  for (int o = 1; o <= h; o++) scanf("%s", s[o] + 1);
  int res = 0;
  for (int o = 1; o <= h; o++)
    for (int i = 1; i <= w; i++) res = max(res, bfs(o, i));
  printf("%d\n", res);
  return 0;
}
