#include <bits/stdc++.h>
using namespace std;
int N, M, ans;
char s[25][25];
const int dir[][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
int BFS(int a, int b) {
  int vis[25][25];
  memset(vis, 0, sizeof(vis));
  queue<pair<int, int>> q;
  int ans = 0;
  q.push({a, b});
  while (!q.empty()) {
    auto p = q.front();
    q.pop();
    a = p.first;
    b = p.second;
    ans = max(ans, vis[a][b]);
    for (int i = (0); i < (4); i++) {
      int x = a + dir[i][0];
      int y = b + dir[i][1];
      if (x < 1 || x > N || y < 1 || y > M || vis[x][y] > 0 || s[x][y] != '.')
        continue;
      vis[x][y] = vis[a][b] + 1;
      q.push({x, y});
    }
  }
  return ans;
}
int main() {
  cin >> N >> M;
  for (int i = (1); i < (N + 1); i++)
    for (int j = (1); j < (M + 1); j++) cin >> s[i][j];
  for (int i = (1); i < (N + 1); i++) {
    for (int j = (1); j < (M + 1); j++) {
      if (s[i][j] == '.') {
        ans = max(ans, BFS(i, j));
      }
    }
  }
  cout << ans;
  return 0;
}
