#include <bits/stdc++.h>
using namespace std;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int H, W;
char S[25][25];
int bfs(pair<int, int> u) {
  vector<vector<int>> dis(25, vector<int>(25, 0));
  queue<pair<int, int>> q;
  q.push(u);
  while (!q.empty()) {
    pair<int, int> v;
    v = q.front();
    q.pop();
    int vx = v.first;
    int vy = v.second;
    for (int i = 0; i < 4; i++) {
      int nx, ny;
      nx = vx + dx[i];
      ny = vy + dy[i];
      if (nx < 0 || nx >= W || ny < 0 || ny >= H) continue;
      if (S[ny][nx] == '#') continue;
      if (dis[ny][nx] != 0) continue;
      dis[ny][nx] = dis[vy][vx] + 1;
      q.push({nx, ny});
    }
  }
  int ma = 0;
  for (int i = 0; i < H; i++)
    ma = max(ma, *max_element(dis[i].begin(), dis[i].end()));
  return ma;
}
int main() {
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> S[i][j];
    }
  }
  queue<pair<int, int>> q;
  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (S[i][j] == '.') ans = max(ans, bfs({i, j}));
    }
  }
  cout << ans << endl;
  return 0;
}
