#include <bits/stdc++.h>
using namespace std;
const int maxn = 25;
int h, w;
string s[maxn];
bool vis[maxn][maxn];
int dis[maxn][maxn], re;
queue<pair<int, int> > q;
void bfs(int u, int v) {
  if (s[u][v] == '#') return;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      dis[i][j] = 0;
      vis[i][j] = 0;
    }
  }
  int cx = u, cy = v;
  dis[cx][cy] = 0;
  vis[cx][cy] = 1;
  q.push({cx, cy});
  while (q.size()) {
    cx = q.front().first, cy = q.front().second;
    q.pop();
    re = max(re, dis[cx][cy]);
    for (int i = -1; i <= 1; i++) {
      for (int j = -1; j <= 1; j++)
        if (!i || !j) {
          int x = cx + i, y = cy + j;
          if (x == h || x < 0 || y == w || y < 0) continue;
          if (vis[x][y]) continue;
          if (s[x][y] == '#') continue;
          dis[x][y] = dis[cx][cy] + 1;
          vis[x][y] = 1;
          q.push({x, y});
        }
    }
  }
}
int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> s[i][j];
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      bfs(i, j);
    }
  }
  cout << re;
  return 0;
}
