#include <bits/stdc++.h>
using namespace ::std;
template <class T1, class T2>
istream& operator>>(istream& I, pair<T1, T2>& p) {
  return I >> p.first >> p.second;
}
template <class T1, class T2>
ostream& operator<<(ostream& O, const pair<T1, T2>& p) {
  return O << '(' << p.first << ' ' << p.second << ')';
}
template <class T>
istream& operator>>(istream& I, vector<T>& v) {
  for (T& e : v) I >> e;
  return I;
}
template <class T>
ostream& operator<<(ostream& O, const vector<T>& v) {
  for (const T& e : v) O << e << ' ';
  return O;
}
template <class T>
ostream& operator<<(ostream& O, const unordered_set<T>& v) {
  for (const T& e : v) O << e << ' ';
  return O;
}
template <class T>
ostream& operator<<(ostream& O, const set<T>& v) {
  for (const T& e : v) O << e << ' ';
  return O;
}
template <class T>
ostream& operator<<(ostream& O, const unordered_multiset<T>& v) {
  for (const T& e : v) O << e << ' ';
  return O;
}
template <class T>
ostream& operator<<(ostream& O, const multiset<T>& v) {
  for (const T& e : v) O << e << ' ';
  return O;
}
template <class T1, class T2>
ostream& operator<<(ostream& O, const unordered_map<T1, T2>& v) {
  for (const auto& e : v) O << e << ' ';
  return O;
}
template <class T1, class T2>
ostream& operator<<(ostream& O, const map<T1, T2>& v) {
  for (const auto& e : v) O << e << ' ';
  return O;
}
template <class T>
istream& operator>>(istream& I, deque<T>& v) {
  for (T& e : v) I >> e;
  return I;
}
template <class T>
ostream& operator<<(ostream& O, const deque<T>& v) {
  for (const T& e : v) O << e << ' ';
  return O;
}
char grid[21][21];
const long long dx[]{1, 0, -1, 0}, dy[]{0, 1, 0, -1};
long long n, m;
long long valid(long long i, long long N) { return i >= 0 && i < N; }
long long get(pair<long long, long long> from) {
  queue<pair<long long, long long> > q;
  q.emplace(from);
  map<pair<long long, long long>, long long> dist;
  dist[from] = 0;
  long long ans = 0;
  while (q.size()) {
    auto now = q.front();
    q.pop();
    for (long long i = 0; i < 4; i++) {
      long long next_i = dx[i] + now.first;
      long long next_j = dy[i] + now.second;
      if (dist.count({next_i, next_j}) || !valid(next_i, n) ||
          !valid(next_j, m) || grid[next_i][next_j] == '#')
        continue;
      q.emplace(next_i, next_j);
      dist[{next_i, next_j}] = dist[now] + 1;
      ans = max(ans, dist[{next_i, next_j}]);
    }
  }
  return ans;
}
void _main() {
  cin >> n >> m;
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++) cin >> grid[i][j];
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      ans = max(ans, get(make_pair(i, j)));
    }
  }
  cout << ans;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long _t = 1;
  while (_t--) _main();
  return 0;
}
