#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MAX_H = 21;
const int MAX_W = 21;
int H, W;
char maze[MAX_H][MAX_W];
int cnt[MAX_H][MAX_W];
int main() {
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> maze[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      queue<P> q;
      q.push(P(i, j));
      memset(cnt, -1, sizeof(cnt));
      cnt[i][j] = 0;
      while (!q.empty()) {
        P p = q.front();
        q.pop();
        int x = p.first;
        int y = p.second;
        if (0 <= x + 1 && x + 1 < H && 0 <= y && y < W && cnt[x + 1][y] == -1 &&
            maze[x + 1][y] == '.') {
          cnt[x + 1][y] = cnt[x][y] + 1;
          ans = max(ans, cnt[x + 1][y]);
          q.push(P(x + 1, y));
        }
        if (0 <= x - 1 && x - 1 < H && 0 <= y && y < W && cnt[x - 1][y] == -1 &&
            maze[x - 1][y] == '.') {
          cnt[x - 1][y] = cnt[x][y] + 1;
          ans = max(ans, cnt[x - 1][y]);
          q.push(P(x - 1, y));
        }
        if (0 <= x && x < H && 0 <= y + 1 && y + 1 < W && cnt[x][y + 1] == -1 &&
            maze[x][y + 1] == '.') {
          cnt[x][y + 1] = cnt[x][y] + 1;
          ans = max(ans, cnt[x][y + 1]);
          q.push(P(x, y + 1));
        }
        if (0 <= x && x < H && 0 <= y - 1 && y - 1 < W && cnt[x][y - 1] == -1 &&
            maze[x][y - 1] == '.') {
          cnt[x][y - 1] = cnt[x][y] + 1;
          ans = max(ans, cnt[x][y - 1]);
          q.push(P(x, y - 1));
        }
      }
    }
  }
  cout << ans << endl;
}
