#include <bits/stdc++.h>
using namespace std;
char mat[22][22];
int n, m, res, in, jn, iv, jv;
const int di[]{0, 0, 1, -1};
const int dj[]{1, -1, 0, 0};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) cin >> (mat[i] + 1);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) {
      vector<vector<int>> d(n + 1, vector<int>(m + 1, 0));
      d[i][j] = 0;
      queue<pair<int, int>> q;
      q.emplace(i, j);
      while (!q.empty()) {
        tie(in, jn) = q.front();
        q.pop();
        for (int dir = 0; dir < 4; ++dir) {
          iv = in + di[dir];
          jv = jn + dj[dir];
          if (iv > 0 && jv > 0 && iv < n + 1 && jv < m + 1 && !d[iv][jv] &&
              mat[iv][jv] == '.')
            d[iv][jv] = d[in][jn] + 1, res = max(res, d[iv][jv]),
            q.emplace(iv, jv);
        }
      }
    }
  cout << res;
  return 0;
}
