#include <bits/stdc++.h>
using namespace std;
template <typename T>
void __read(T &a) {
  cin >> a;
}
template <typename T, typename... Args>
void __read(T &a, Args &...args) {
  cin >> a;
  __read(args...);
}
constexpr long long M7 = 1000000007ll;
constexpr long long M9 = 1000000009ll;
constexpr long long MFFT = 998244353ll;
template <class T>
void outv(T &a) {
  for (auto &x : a) cout << x << ' ';
}
static mt19937 rnd(static_cast<unsigned>(
    chrono::steady_clock::now().time_since_epoch().count()));
template <class T>
static auto __super_speed__ = (ios_base::sync_with_stdio(0), cin.tie(0));
int32_t main() {
  long long n, m;
  __read(n, m);
  vector<string> a(n);
  for (long long i = 0; i < n; ++i) {
    cin >> a[i];
  }
  long long ans = 0;
  for (long long x1 = 0; x1 < n; ++x1) {
    for (long long y1 = 0; y1 < m; ++y1) {
      if (a[x1][y1] == '#') {
        continue;
      }
      for (long long x2 = 0; x2 < n; ++x2) {
        for (long long y2 = 0; y2 < m; ++y2) {
          queue<pair<long long, long long>> q;
          q.emplace(x1, y1);
          vector<vector<long long>> dist(n, vector<long long>(m, M7));
          dist[x1][y1] = 0;
          while (!q.empty()) {
            auto [x, y] = q.front();
            q.pop();
            if (x > 0 && dist[x - 1][y] == M7 && a[x - 1][y] != '#') {
              dist[x - 1][y] = dist[x][y] + 1;
              q.emplace(x - 1, y);
            }
            if (x + 1 < n && dist[x + 1][y] == M7 && a[x + 1][y] != '#') {
              dist[x + 1][y] = dist[x][y] + 1;
              q.emplace(x + 1, y);
            }
            if (y > 0 && dist[x][y - 1] == M7 && a[x][y - 1] != '#') {
              dist[x][y - 1] = dist[x][y] + 1;
              q.emplace(x, y - 1);
            }
            if (y + 1 < m && dist[x][y + 1] == M7 && a[x][y + 1] != '#') {
              dist[x][y + 1] = dist[x][y] + 1;
              q.emplace(x, y + 1);
            }
          }
          if (dist[x2][y2] != M7) {
            ans = max(ans, dist[x2][y2]);
          }
        }
      }
    }
  }
  cout << ans;
  return 0;
}
