#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug& operator<<(const c&) {
    return *this;
  }
};
const long long mxn = 25;
string grid[mxn];
long long vis[mxn][mxn];
long long n, m;
long long dx[] = {-1, 1, 0, 0};
long long dy[] = {0, 0, -1, 1};
long long ans[mxn][mxn];
bool valid(long long x, long long y) {
  return (x >= 0 and x < n and y >= 0 and y < m);
}
pair<long long, long long> bfs(long long x, long long y) {
  memset(vis, -1, sizeof(vis));
  vis[x][y] = 0;
  long long se, ed;
  queue<pair<long long, long long>> q;
  q.push({x, y});
  while (!q.empty()) {
    tie(se, ed) = q.front();
    q.pop();
    for (long long i = 0; i < 4; i++) {
      long long nx = se + dx[i];
      long long ny = ed + dy[i];
      if (valid(nx, ny) and vis[nx][ny] == -1 and grid[nx][ny] == '.') {
        vis[nx][ny] = 1 + vis[se][ed];
        ans[nx][ny] = max(ans[nx][ny], vis[nx][ny]);
        q.push({nx, ny});
      }
    }
  }
  return {se, ed};
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (long long i = 0; i < n; i++) cin >> grid[i];
  long long x = -1, y = -1;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) {
      if (grid[i][j] == '.') {
        x = i, y = j;
        break;
      }
    }
    if (x != -1) break;
  }
  pair<long long, long long> p = bfs(x, y);
  bfs(p.first, p.second);
  long long res = 0;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      res = max(res, ans[i][j]);
    }
  }
  cout << res << "\n";
  return 0;
}
