#include <bits/stdc++.h>
using namespace std;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int H, W;
string S[21];
int bfs(int x, int y) {
  queue<pair<int, pair<int, int> > > que;
  que.push({0, {x, y}});
  int ret = 0;
  bool visited[21][21] = {};
  while (que.size()) {
    pair<int, pair<int, int> > p = que.front();
    que.pop();
    int d = p.first;
    int x = p.second.first;
    int y = p.second.second;
    ret = max(ret, d);
    for (int i = 0; i < 4; i++) {
      int xx = x + dx[i];
      int yy = y + dy[i];
      if (xx < 0 || xx >= H || yy < 0 || yy >= W) continue;
      if (S[xx][yy] == '#') continue;
      if (visited[xx][yy]) continue;
      visited[xx][yy] = true;
      que.push({d + 1, {xx, yy}});
    }
  }
  return ret;
}
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> H >> W;
  for (int i = 0; i < H; i++) cin >> S[i];
  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (S[i][j] == '.') {
        ans = max(ans, bfs(i, j));
      }
    }
  }
  cout << ans << endl;
  return 0;
}
