#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 7;
const long long INF = 2e9;
int move_x[4] = {-1, +1, 0, 0};
int move_y[4] = {0, 0, -1, +1};
bool vis[21][21];
char grid[21][21];
int n, m;
bool check(int dx, int dy) {
  if (dx >= 0 && dx < n && dy >= 0 && dy < m && !vis[dx][dy] &&
      grid[dx][dy] == '.')
    return true;
  return false;
}
int bfs(int x1, int y1) {
  memset(vis, false, sizeof vis);
  queue<pair<pair<int, int>, int> > q;
  q.push(pair<pair<int, int>, int>(pair<int, int>(x1, y1), 0));
  int best = 0;
  while (!q.empty()) {
    int currx = q.front().first.first;
    int curry = q.front().first.second;
    int dist = q.front().second;
    best = max(best, dist);
    q.pop();
    for (int i = 0; i < 4; i++) {
      int dx = currx + move_x[i], dy = curry + move_y[i];
      if (check(dx, dy)) {
        q.push(pair<pair<int, int>, int>(pair<int, int>(dx, dy), dist + 1));
        vis[dx][dy] = true;
      }
    }
  }
  return best;
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> grid[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (grid[i][j] == '#') continue;
      ans = max(ans, bfs(i, j));
    }
  }
  cout << ans << '\n';
  return 0;
}
