#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const int N = 2e5 + 11;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, -1, 0, 1};
int a[30][30], sum, ans = INT_MIN;
int n, k, m;
queue<pair<int, int> > q;
vector<pair<int, int> > v;
bool ok(pair<int, int> p) {
  if (p.first < 0 || p.first > n || p.second < 0 || p.second > m) return 0;
  if (a[p.first][p.second] == 0) return 0;
  return 1;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cerr.tie(0);
  cout.tie(0);
  cin >> n >> m;
  int bb = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      char x;
      cin >> x;
      if (x == '.')
        a[i][j] = 1, v.push_back(make_pair(i, j));
      else
        a[i][j] = 0;
    }
  }
  for (int e = 0; e <= (int)((v).size()) - 1; e++) {
    q.push(v[e]);
    map<pair<int, int>, int> dist;
    while (!q.empty()) {
      pair<int, int> pe = q.front();
      q.pop();
      for (int i = 0; i < 4; i++) {
        pair<int, int> step = make_pair(pe.first + dx[i], pe.second + dy[i]);
        if (!dist[step] && ok(step)) {
          dist[step] = dist[pe] + 1;
          q.push(step);
        }
      }
    }
    for (auto it : dist) ans = max(ans, it.second);
  }
  cout << ans << '\n';
  return 0;
}
