#include <bits/stdc++.h>
using namespace std;
char s[21][21];
int h, w;
int dx[4] = {-1, +1, 0, 0};
int dy[4] = {0, 0, -1, +1};
int bfs(int k, int l) {
  int vst[h][w], cst[h][w];
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) {
      vst[i][j] = 0;
      cst[i][j] = 0;
    }
  queue<pair<int, int> > q;
  q.push(make_pair(k, l));
  cst[k][l] = 0;
  vst[k][l] = 1;
  int mx = 0;
  while (!q.empty()) {
    int x = q.front().first;
    int y = q.front().second;
    q.pop();
    for (int i = 0; i < 4; i++) {
      int m = x + dx[i];
      int n = y + dy[i];
      if (m < 0 || n < 0 || m > h || n > w || s[m][n] == '#')
        continue;
      else if (vst[m][n] == 0) {
        vst[m][n] = 1;
        cst[m][n] = 1 + cst[x][y];
        q.push(make_pair(m, n));
        mx = max(mx, cst[m][n]);
      }
    }
  }
  return mx;
}
int solve() {
  cin >> h >> w;
  int maxi = 0;
  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++) {
      if (s[i][j] == '.') {
        maxi = max(maxi, bfs(i, j));
      }
    }
  }
  cout << maxi << endl;
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  t = 1;
  while (t--) {
    solve();
  }
}
