#include <bits/stdc++.h>
using namespace std;
int h, w;
char s[30][30];
bool used[30][30];
int d[30][30];
int ans;
struct point {
  int l, r, d;
} p0;
queue<point> que;
void bfs(int x, int y) {
  p0.l = x, p0.r = y, p0.d = 0;
  que.push(p0);
  while (!que.empty()) {
    point p1 = que.front();
    que.pop();
    used[p1.l][p1.r] = true;
    int a = p1.l;
    int b = p1.r;
    ans = max(ans, p1.d);
    if (a != 1) {
      if (s[a - 1][b] == '.' && !used[a - 1][b]) {
        p0.l = a - 1, p0.r = b, p0.d = p1.d + 1;
        used[a - 1][b] = true;
        que.push(p0);
      }
    }
    if (a != h) {
      if (s[a + 1][b] == '.' && !used[a + 1][b]) {
        p0.l = a + 1, p0.r = b, p0.d = p1.d + 1;
        used[a + 1][b] = true;
        que.push(p0);
      }
    }
    if (b != 1) {
      if (s[a][b - 1] == '.' && !used[a][b - 1]) {
        p0.l = a, p0.r = b - 1, p0.d = p1.d + 1;
        used[a][b - 1] = true;
        que.push(p0);
      }
    }
    if (b != w) {
      if (s[a][b + 1] == '.' && !used[a][b + 1]) {
        p0.l = a, p0.r = b + 1, p0.d = p1.d + 1;
        used[a][b + 1] = true;
        que.push(p0);
      }
    }
  }
  return;
}
int main() {
  cin >> h >> w;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      cin >> s[i][j];
    }
  }
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      for (int l = 1; l <= h; l++) {
        for (int r = 1; r <= w; r++) {
          used[l][r] = false;
        }
      }
      bfs(i, j);
    }
  }
  cout << ans << endl;
  return 0;
}
