#include <bits/stdc++.h>
using namespace std;
int H, W;
bool S[21][21];
bool visit[21][21];
int dist[21][21];
int solve(int i, int j) {
  fill(visit[0], visit[21], false);
  fill(dist[0], dist[21], 0);
  queue<pair<int, int>> q;
  q.push(make_pair(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.push(make_pair(h, w - 1));
      dist[h][w - 1] = dist[h][w] + 1;
      m = max(m, dist[h][w - 1]);
    }
    if (w < W - 1 && S[h][w + 1] && !visit[h][w + 1]) {
      q.push(make_pair(h, w + 1));
      dist[h][w + 1] = dist[h][w] + 1;
      m = max(m, dist[h][w + 1]);
    }
    if (h > 0 && S[h - 1][w] && !visit[h - 1][w]) {
      q.push(make_pair(h - 1, w));
      dist[h - 1][w] = dist[h][w] + 1;
      m = max(m, dist[h - 1][w]);
    }
    if (h < H - 1 && S[h + 1][w] && !visit[h + 1][w]) {
      q.push(make_pair(h + 1, w));
      dist[h + 1][w] = dist[h][w] + 1;
      m = max(m, dist[h + 1][w]);
    }
  }
  return m;
}
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]) {
        ans = max(ans, solve(i, j));
      }
    }
  }
  cout << ans << endl;
  return 0;
}
