#include <bits/stdc++.h>
using namespace std;
const int mod = 100000007;
const int inf = 100005;
const int N = 3e5, M = N;
long long i, j, n, m, idx, cnt;
string d[31];
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
int cal(int x, int y) {
  queue<pair<int, pair<int, int>>> q;
  int u[31][31];
  int vis[31][31], ii, jj;
  for (ii = 0; ii < 31; ii++) {
    for (jj = 0; jj < 31; jj++) vis[ii][jj] = 0, u[ii][jj] = inf;
  }
  u[x][y] = 0;
  q.push({x, {y, 0}});
  while (!q.empty()) {
    pair<int, pair<int, int>> p = q.front();
    q.pop();
    if (vis[p.first][p.second.first]) continue;
    vis[p.first][p.second.first] = 1;
    for (idx = 0; idx < 4; idx++) {
      int x1 = p.first + dx[idx];
      int y1 = p.second.first + dy[idx];
      if (x1 < 0 || x1 >= n || y1 < 0 || y1 >= m) continue;
      if (d[x1][y1] == '#') {
        u[x1][y1] = inf;
        continue;
      }
      u[x1][y1] = min(u[x1][y1], p.second.second + 1);
      q.push({x1, {y1, p.second.second + 1}});
    }
  }
  int ans = 0;
  for (ii = 0; ii < n; ii++) {
    for (jj = 0; jj < m; jj++) {
      if (u[ii][jj] == inf) continue;
      ans = max(ans, u[ii][jj]);
    }
  }
  return ans;
}
void solve() {
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cin >> d[i][j];
    }
  }
  int ans = 0;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      ans = max(ans, cal(i, j));
    }
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
