#include <bits/stdc++.h>
using namespace std;
char grid[30][30];
int h, w;
int bfs(pair<int, int> start) {
  queue<pair<int, int>> q;
  int dist[30][30] = {{-1}};
  dist[start.first][start.second] = 0;
  int dx[4] = {1, -1, 0, 0};
  int dy[4] = {0, 0, 1, -1};
  q.push(start);
  int distn;
  while (!q.empty()) {
    pair<int, int> now = q.front();
    q.pop();
    distn = dist[now.first][now.second];
    for (int i = 0; i < 4; i++) {
      if (now.first + dx[i] >= 0 && now.first + dx[i] < h &&
          now.second + dy[i] >= 0 && now.second + dy[i] < w &&
          dist[now.first + dx[i]][now.second + dy[i]] == -1 &&
          grid[now.first + dx[i]][now.second + dy[i]] == '.') {
        q.push(make_pair(now.first + dx[i], now.second + dy[i]));
        dist[now.first + dx[i]][now.second + dy[i]] = distn + 1;
      }
    }
  }
  return distn;
}
int main(int argc, char const *argv[]) {
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> grid[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (grid[i][j] == '.') {
        ans = max(ans, bfs(make_pair(i, j)));
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
