#include <bits/stdc++.h>
using namespace std;
const int N = 22;
const int inf = 123456789;
int n, m;
char mat[N][N];
bool ok(int x, int y) { return (x >= 0 && y >= 0 && x < n && y < m); }
int go(int x, int y) {
  queue<pair<int, int> > q;
  q.push({x, y});
  int dist[N][N] = {};
  bool used[N][N] = {};
  used[x][y] = 1;
  while (!q.empty()) {
    int xx = q.front().first, yy = q.front().second;
    q.pop();
    used[xx][yy] = 1;
    if (ok(xx - 1, yy) && !used[xx - 1][yy] && mat[xx - 1][yy] != '#') {
      q.push({xx - 1, yy});
      dist[xx - 1][yy] = dist[xx][yy] + 1;
    }
    if (ok(xx + 1, yy) && !used[xx + 1][yy] && mat[xx + 1][yy] != '#') {
      q.push({xx + 1, yy});
      dist[xx + 1][yy] = dist[xx][yy] + 1;
    }
    if (ok(xx, yy - 1) && !used[xx][yy - 1] && mat[xx][yy - 1] != '#') {
      q.push({xx, yy - 1});
      dist[xx][yy - 1] = dist[xx][yy] + 1;
    }
    if (ok(xx, yy + 1) && !used[xx][yy + 1] && mat[xx][yy + 1] != '#') {
      q.push({xx, yy + 1});
      dist[xx][yy + 1] = dist[xx][yy] + 1;
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      ans = max(ans, dist[i][j]);
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  int ans = 0;
  for (int i = 0; i < n; i++) cin >> mat[i];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (mat[i][j] == '#') continue;
      ans = max(ans, go(i, j));
    }
  }
  cout << ans << endl;
  return 0;
}
