#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
}
int h, w;
vector<vector<int>> ansv(25, vector<int>(25, -1));
vector<vector<char>> s(25, vector<char>(25));
int aaa[25][25][25][25];
int dp(int s_i, int s_j) {
  if (s[s_i][s_j] == '#') {
    return -1;
  }
  int n_i = s_i;
  int n_j = s_j;
  queue<pair<pair<int, int>, int>> q;
  int n_p = 0;
  aaa[s_i][s_j][n_i][n_j] = n_p;
  if (n_i > 0 && aaa[s_i][s_j][n_i - 1][n_j] == -1) {
    q.push(make_pair(make_pair(n_i - 1, n_j), n_p + 1));
  }
  if (n_i < h - 1 && aaa[s_i][s_j][n_i + 1][n_j] == -1) {
    q.push(make_pair(make_pair(n_i + 1, n_j), n_p + 1));
  }
  if (n_j > 0 && aaa[s_i][s_j][n_i][n_j - 1] == -1) {
    q.push(make_pair(make_pair(n_i, n_j - 1), n_p + 1));
  }
  if (n_j < w - 1 && aaa[s_i][s_j][n_i][n_j + 1] == -1) {
    q.push(make_pair(make_pair(n_i, n_j + 1), n_p + 1));
  }
  int ans = 0;
  while (!q.empty()) {
    n_i = q.front().first.first;
    n_j = q.front().first.second;
    n_p = q.front().second;
    aaa[s_i][s_j][n_i][n_j] = n_p;
    q.pop();
    if (s[n_i][n_j] != '#') {
      chmax(ans, n_p);
      if (n_i > 0 && aaa[s_i][s_j][n_i - 1][n_j] == -1) {
        q.push(make_pair(make_pair(n_i - 1, n_j), n_p + 1));
      }
      if (n_i < h - 1 && aaa[s_i][s_j][n_i + 1][n_j] == -1) {
        q.push(make_pair(make_pair(n_i + 1, n_j), n_p + 1));
      }
      if (n_j > 0 && aaa[s_i][s_j][n_i][n_j - 1] == -1) {
        q.push(make_pair(make_pair(n_i, n_j - 1), n_p + 1));
      }
      if (n_j < w - 1 && aaa[s_i][s_j][n_i][n_j + 1] == -1) {
        q.push(make_pair(make_pair(n_i, n_j + 1), n_p + 1));
      }
    }
  }
  return ans;
}
int main() {
  for (long long i = 0; i < (long long)(25); ++i)
    for (long long j = 0; j < (long long)(25); ++j)
      for (long long k = 0; k < (long long)(25); ++k)
        for (long long l = 0; l < (long long)(25); ++l) {
          aaa[i][j][k][l] = -1;
        }
  cin >> h >> w;
  for (long long i = 0; i < (long long)(h); ++i)
    for (long long j = 0; j < (long long)(w); ++j) cin >> s[i][j];
  int ans = 0;
  for (long long i = 0; i < (long long)(h); ++i)
    for (long long j = 0; j < (long long)(w); ++j) {
      int tmp = dp(i, j);
      chmax(ans, tmp);
    }
  cout << ans << endl;
  return 0;
}
