#include <bits/stdc++.h>
using namespace std;
char s[25][25];
int vis[25][25], n, m, ans = 0;
int xx[4] = {0, 0, 1, -1};
int yy[4] = {1, -1, 0, 0};
int bfs(int x, int y) {
  int ma = 0;
  queue<pair<int, int> > q;
  q.push(make_pair(x, y));
  while (!q.empty()) {
    pair<int, int> p = q.front();
    q.pop();
    for (int i = 0; i < 4; i++) {
      x = p.first + xx[i];
      y = p.second + yy[i];
      if (x <= 0 || y <= 0 || x > n || y > m || s[x][y] == '#' ||
          vis[x][y] != 0) {
        ma = max(ma, vis[p.first][p.second]);
        continue;
      }
      vis[x][y] = vis[p.first][p.second] + 1;
      q.push(make_pair(x, y));
    }
  }
  return ma;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (s[i][j] == '#') continue;
      memset(vis, 0, sizeof(vis));
      ans = max(ans, bfs(i, j));
    }
  }
  cout << ans << endl;
  return 0;
}
