#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
int H, W;
int A[22][22];
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int solve(int r, int c) {
  int d[H][W], ret = 0;
  for (int i = 0; i < (H); i++)
    for (int j = 0; j < (W); j++) d[i][j] = -1;
  d[r][c] = 0;
  queue<pair<int, int>> que;
  que.push({r, c});
  while (que.size()) {
    pair<int, int> p = que.front();
    que.pop();
    int i = p.first, j = p.second;
    for (int k = 0; k < (4); k++) {
      int ii = i + dx[k], jj = j + dy[k];
      if (ii < 0 || ii >= H) continue;
      if (jj < 0 || jj >= W) continue;
      if (A[ii][jj] == 0) continue;
      if (d[ii][jj] == -1) {
        d[ii][jj] = d[i][j] + 1;
        que.push({ii, jj});
      } else if (d[ii][jj] > d[i][j] + 1) {
        d[ii][jj] = d[i][j] + 1;
        que.push({ii, jj});
      }
    }
  }
  for (int i = 0; i < (H); i++)
    for (int j = 0; j < (W); j++) ret = max(ret, d[i][j]);
  return ret;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> H >> W;
  for (int i = 0; i < (H); i++) {
    string S;
    cin >> S;
    for (int j = 0; j < (W); j++) A[i][j] = (S[j] == '.');
  }
  int ans = 0;
  for (int i = 0; i < (H); i++)
    for (int j = 0; j < (W); j++) ans = max(ans, solve(i, j));
  cout << ans << endl;
  return 0;
}
