#include <bits/stdc++.h>
using namespace std;
using ii = pair<int, int>;
using iii = pair<int, ii>;
using ll = long long;
int n, m;
char _mt[30][30];
char mt[30][30];
int32_t main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; ++i) scanf("%s", _mt[i]);
  int ans = 0;
  for (int _i = 0; _i < n; ++_i) {
    for (int _j = 0; _j < m; ++_j) {
      if (_mt[_i][_j] == '#') continue;
      for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++j) mt[i][j] = _mt[i][j];
      queue<iii> q;
      q.push({0, {_i, _j}});
      while (not q.empty()) {
        int d = q.front().first;
        int i = q.front().second.first;
        int j = q.front().second.second;
        q.pop();
        ans = max(ans, d);
        mt[i][j] = '#';
        if (i > 0 and mt[i - 1][j] != '#') q.push({d + 1, {i - 1, j}});
        if (i < n - 1 and mt[i + 1][j] != '#') q.push({d + 1, {i + 1, j}});
        if (j < m - 1 and mt[i][j + 1] != '#') q.push({d + 1, {i, j + 1}});
        if (j > 0 and mt[i][j - 1] != '#') q.push({d + 1, {i, j - 1}});
      }
    }
  }
  cout << ans << endl;
}
