#include <bits/stdc++.h>
using namespace std;
const long long N = 20 + 5, M = 3e5 + 5, mod = 1e9 + 7, mod1 = 998244353,
                mod2 = 1e9 + 9, inf = 1e9 + 7;
const long long infll = 1e18 + 7;
long long n, m, ans;
bool a[N][N];
bool ck[N][N];
long long dx[4] = {0, 1, 0, -1};
long long dy[4] = {1, 0, -1, 0};
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) {
    string s;
    cin >> s;
    for (long long j = 1; j <= m; j++) {
      a[i][j] = (s[j - 1] == '.' ? 0 : 1);
    }
  }
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      memset(ck, 0, sizeof(ck));
      queue<pair<pair<long long, long long>, long long> > qu;
      qu.push({{i, j}, 0});
      ck[i][j] = 1;
      while (!qu.empty()) {
        pair<pair<long long, long long>, long long> t = qu.front();
        qu.pop();
        ans = max(ans, t.second);
        for (long long k = 0; k < 4; k++) {
          long long x = t.first.first + dx[k], y = t.first.second + dy[k];
          if (x == 0 || y == 0 || x == n + 1 || y == m + 1 || a[x][y] ||
              ck[x][y])
            continue;
          ck[x][y] = 1;
          qu.push({{x, y}, t.second + 1});
        }
      }
    }
  }
  cout << ans;
}
