#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int h, w;
char s[22][22];
ll s_y, s_x, g_y, g_x;
ll y, x, depth;
struct Corr {
  ll y;
  ll x;
  ll depth;
};
queue<Corr> q;
ll answer = -1;
int y_vec[] = {0, 0, -1, +1};
int x_vec[] = {-1, +1, 0, 0};
ll bfs() {
  while (!q.empty()) {
    Corr now = q.front();
    q.pop();
    y = now.y, x = now.x, depth = now.depth;
    answer = max(depth, answer);
    for (ll i = 0; i < 4; ++i) {
      Corr next = {y + y_vec[i], x + x_vec[i], depth + 1};
      if (s[next.y][next.x] == '.') {
        s[next.y][next.x] = 'x';
        q.push(next);
      }
    }
  }
  return 0;
}
int main() {
  cin >> h >> w;
  char S[22][22];
  for (int i = 0; i < (22); ++i) {
    for (int j = 0; j < (22); ++j) {
      S[i][j] = '#';
    }
  }
  for (int i = (1); i < (h + 1); ++i) {
    for (int j = (1); j < (w + 1); ++j) {
      cin >> S[i][j];
    }
  }
  for (int i = (1); i < (h + 1); ++i) {
    for (int j = (1); j < (w + 1); ++j) {
      for (int k = 0; k < (22); ++k) {
        for (int t = 0; t < (22); ++t) {
          s[k][t] = S[k][t];
        }
      }
      if (s[i][j] == '#') continue;
      Corr start = {i, j, 0};
      q.push(start);
      int x = bfs();
    }
  }
  cout << answer << endl;
  return 0;
}
