#include <bits/stdc++.h>
using namespace std;
template <typename T>
void _dbg(const char* _s, T _h) {
  cerr << _s << " = " << _h << "\n";
}
template <typename T, typename... Ts>
void _dbg(const char* _s, T _h, Ts... _t) {
  int _b = 0;
  while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',') cerr << *_s++;
  cerr << " = " << _h << ",";
  _dbg(_s + 1, _t...);
}
const int64_t INF = static_cast<int64_t>(1e9) + 7;
const int64_t LINF = INF * INF;
const int MAXN = static_cast<int>(1e6) + 17;
using pii = pair<int, int>;
void solve() {
  int n, m;
  cin >> n >> m;
  vector<vector<char>> field(n + 2, vector<char>(m + 2, '#'));
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      char c;
      cin >> c;
      field[i][j] = c;
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      if (field[i][j] == '#') {
        continue;
      }
      queue<pair<pii, int>> q;
      q.push({{i, j}, 0});
      vector<vector<char>> visited(n + 2, vector<char>(m + 2, 0));
      while (!q.empty()) {
        auto p = q.front().first;
        auto d = q.front().second;
        q.pop();
        for (int i : {-1, 1}) {
          pii cand = {p.first + i, p.second};
          if (!visited[cand.first][cand.second] &&
              field[cand.first][cand.second] == '.') {
            visited[cand.first][cand.second] = 1;
            q.push({cand, d + 1});
            ans = max(ans, d + 1);
          }
          cand = {p.first, p.second + i};
          if (!visited[cand.first][cand.second] &&
              field[cand.first][cand.second] == '.') {
            visited[cand.first][cand.second] = 1;
            q.push({cand, d + 1});
            ans = max(ans, d + 1);
          }
        }
      }
    }
  }
  cout << ans << '\n';
}
int main() {
  cin.tie(nullptr);
  cout.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int q = 1;
  for (int i = 0; i < q; ++i) {
    solve();
  }
}
