#include <bits/stdc++.h>
using namespace std;
char S[22][22] = {'#'};
int dist[22][22];
int dx[4] = {0, 0, -1, 1}, dy[4] = {1, -1, 0, 0};
int bfs(int sx, int sy) {
  queue<pair<int, int>> q;
  q.push({sx, sy});
  int kyori = 0;
  while (!q.empty()) {
    pair<int, int> p = q.front();
    q.pop();
    int x = p.first, y = p.second;
    for (int i = 0; i < 4; i++) {
      int nx = x + dx[i], ny = y + dy[i];
      if (dist[nx][ny] == -1 && S[nx][ny] != '#') {
        dist[nx][ny] = dist[x][y] + 1;
        q.push({nx, ny});
        kyori = dist[nx][ny];
      }
    }
  }
  return kyori;
}
int main() {
  int H, W;
  cin >> H >> W;
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      cin >> S[i][j];
    }
  }
  int sx, sy;
  int ans = 0;
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      sx = i;
      sy = j;
      dist[22][22] = {-1};
      ans = max(ans, bfs(sx, sy));
    }
  }
  cout << ans;
  return 0;
}
