#include <bits/stdc++.h>
using namespace std;
int x[] = {0, 1, 0, -1};
int y[] = {1, 0, -1, 0};
bool M[21][21];
int H, W;
bool valid(int r, int c) {
  if (r < H && r >= 0 && c < W && c >= 0)
    return true;
  else
    return false;
}
bool v[21][21];
int BFS(int r, int c) {
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      v[i][j] = 0;
    }
  }
  queue<pair<int, int> > q;
  q.push({r, c});
  v[r][c] = 1;
  q.push({-1, -1});
  int cnt = 0;
  while (!q.empty()) {
    pair<int, int> p = q.front();
    q.pop();
    if (p.first == -1) {
      cnt++;
      if (!q.empty()) {
        q.push({-1, -1});
        continue;
      } else {
        break;
      }
    }
    r = p.first;
    c = p.second;
    for (int i = 0; i < 4; i++) {
      int R = r + x[i];
      int C = c + y[i];
      if (valid(R, C) && M[R][C] && !v[R][C]) {
        q.push({R, C});
        v[r][c] = 1;
      }
    }
  }
  return cnt - 1;
}
int main() {
  cin >> H >> W;
  char c;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> c;
      if (c == '.') M[i][j] = 1;
    }
  }
  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (M[i][j]) {
        int x = BFS(i, j);
        ans = max(ans, x);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
