#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int d[505][505];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n * m; i++) {
    for (int j = 0; j < n * m; j++) {
      if (i != j)
        d[i][j] = 74751;
      else
        d[i][j] = 0;
    }
  }
  string s[25];
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  int dx[] = {-1, 1, 0, 0};
  int dy[] = {0, 0, 1, -1};
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i][j] == '#') {
        d[i * n + j][i * n + j] = 74751;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i][j] == '#') continue;
      int idx1 = i * n + j;
      for (int k = 0; k < 4; k++) {
        int xx = i + dx[k];
        int yy = j + dy[k];
        if (xx < 0 || xx >= n) continue;
        if (yy < 0 || yy >= m) continue;
        if (s[xx][yy] == '#') continue;
        int idx2 = xx * n + yy;
        d[idx1][idx2] = d[idx2][idx1] = 1;
      }
    }
  }
  for (int k = 0; k < n * m; k++) {
    for (int i = 0; i < n * m; i++) {
      for (int j = 0; j < n * m; j++) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
  int mx = 0;
  for (int i = 0; i < n * m; i++) {
    for (int j = 0; j < n * m; j++) {
      if (d[i][j] < 74751) {
        mx = max(mx, d[i][j]);
      }
    }
  }
  cout << mx << '\n';
}
