#include <bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
using seika = string;
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;
inline void print() { cout << endl; }
template <typename First, typename... Rest>
void print(const First &first, const Rest &...rest) {
  cout << first << ' ';
  print(rest...);
}
void solve() {
  int h, w;
  cin >> h >> w;
  akari<seika> g(h);
  for (int i = 0; i < h; i++) {
    cin >> g[i];
  }
  int ans = 0;
  for (int s = 0; s < h * w; s++) {
    queue<int> q;
    akari<int> ds(h * w, -1);
    ds[s] = 0;
    q.push(s);
    while (!q.empty()) {
      int v = q.front();
      q.pop();
      int x = v % w, y = v / w;
      for (int d = 0; d < 4; d++) {
        int nx = x + (d & 2 ? (d & 1 ? 1 : -1) : 0);
        int ny = y + (d & 2 ? 0 : (d & 1 ? 1 : -1));
        if (0 <= nx && nx < w && 0 <= ny && ny < h && g[ny][nx] == '.' &&
            ds[nx + ny * w] == -1) {
          ds[nx + ny * w] = ds[v] + 1;
          q.push(nx + ny * w);
        }
      }
    }
    ans = max(ans, *max_element(ds.begin(), ds.end()));
  }
  cout << ans << endl;
}
int main() {
  solve();
  return 0;
}
