#include <bits/stdc++.h>
using namespace std;
string s[22];
int n, m, vis[22][22];
queue<pair<int, int>> q;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, 1, -1};
int BFS(int st, int en) {
  memset(vis, -1, sizeof(vis));
  int i, x, xx, y, yy, mx = 0;
  vis[st][en] = 0;
  q.push({st, en});
  while (!q.empty()) {
    x = q.front().first;
    y = q.front().second;
    q.pop();
    for (i = 0; i < 4; i++) {
      xx = x + dx[i];
      yy = y + dy[i];
      if (xx >= 0 && xx < n && yy >= 0 && yy < m && s[xx][yy] == '.' &&
          vis[xx][yy] == -1) {
        vis[xx][yy] = vis[x][y] + 1;
        mx = max(mx, vis[xx][yy]);
        q.push({xx, yy});
      }
    }
  }
  return mx;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int i, j, ans = 0;
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    cin >> s[i];
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (s[i][j] == '.') {
        ans = max(ans, BFS(i, j));
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
