#include <bits/stdc++.h>
using namespace std;
int H, W;
bool S[21][21];
bool visit[21][21];
int dist[21][21];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> H >> W;
  int cnt = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      char c;
      cin >> c;
      if (c == '.') {
        S[i][j] = true;
        cnt++;
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (S[i][j]) {
        fill(visit[0], visit[21], false);
        fill(dist[0], dist[21], 0);
        queue<pair<int, int>> q;
        q.emplace(i, j);
        int m = 0;
        while (!q.empty()) {
          int h, w;
          tie(h, w) = q.front();
          q.pop();
          visit[h][w] = true;
          if (w > 0 && S[h][w - 1] && !visit[h][w - 1]) {
            q.emplace(h, w - 1);
            dist[h][w - 1] = dist[h][w] + 1;
            ans = max(ans, dist[h][w - 1]);
          }
          if (w < W - 1 && S[h][w + 1] && !visit[h][w + 1]) {
            q.emplace(h, w + 1);
            dist[h][w + 1] = dist[h][w] + 1;
            ans = max(ans, dist[h][w + 1]);
          }
          if (h > 0 && S[h - 1][w] && !visit[h - 1][w]) {
            q.emplace(h - 1, w);
            dist[h - 1][w] = dist[h][w] + 1;
            ans = max(ans, dist[h - 1][w]);
          }
          if (h < H - 1 && S[h + 1][w] && !visit[h + 1][w]) {
            q.emplace(h + 1, w);
            dist[h + 1][w] = dist[h][w] + 1;
            ans = max(ans, dist[h + 1][w]);
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
