#include <bits/stdc++.h>
using namespace std;
int w, h;
char arr[25][25];
int vis[25][25];
int xx[] = {+1, 0, -1, 0};
int yy[] = {0, +1, 0, -1};
int check(int i, int j) {
  if (i < 0 or i >= h or j < 0 or j >= w or arr[i][j] == '#') return 0;
  return 1;
}
int bfs(int i, int j) {
  int mx = -1;
  deque<pair<int, int>> dq;
  memset(vis, -1, sizeof(vis));
  dq.push_back({i, j});
  vis[i][j] = 0;
  while (dq.size()) {
    int px = dq.front().first;
    int py = dq.front().second;
    dq.pop_front();
    for (int i = 0; i < 4; i++) {
      int nx = px + xx[i];
      int ny = py + yy[i];
      if (check(nx, ny) != 0 and vis[nx][ny] == -1 and arr[i][j] != '#') {
        vis[nx][ny] = vis[px][py] + 1;
        mx = max(vis[nx][ny], mx);
        dq.push_back({nx, ny});
      }
    }
  }
  return mx;
}
int main() {
  ios_base::sync_with_stdio(0);
  int t = 1;
  int T = t;
  while (t--) {
    cin >> h >> w;
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        cin >> arr[i][j];
      }
    }
    int mx = 0;
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        if (arr[i][j] != '#') {
          mx = max(mx, bfs(i, j));
        }
      }
    }
    cout << mx << '\n';
  }
  return 0;
}
