#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
using vP = vector<P>;
using vPP = vector<vP>;
using vPl = vector<Pl>;
const int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 62) - 1;
ll ceil(const ll& a, const ll& b) { return ((a) + (b)-1) / b; }
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int h, w;
  cin >> h >> w;
  vs s(h);
  for (ll i = 0; i < h; i++) cin >> s[i];
  int ans = 0;
  for (ll i = 0; i < h; i++) {
    for (ll j = 0; j < w; j++) {
      if (s[i][j] == '#') continue;
      vii d(h, vi(w));
      queue<P> q;
      vector<vb> seen(h, vb(w));
      q.emplace(i, j);
      d[i][j] = 0;
      while (int(q.size())) {
        int y = q.front().first;
        int x = q.front().second;
        q.pop();
        seen[y][x] = true;
        for (ll dis = 0; dis < 4; dis++) {
          int ny = dy[dis] + y;
          int nx = dx[dis] + x;
          if (ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
          if (s[ny][nx] == '#' || seen[ny][nx]) continue;
          d[ny][nx] = d[y][x] + 1;
          chmax(ans, d[ny][nx]);
          q.emplace(ny, nx);
        }
      }
    }
  }
  cout << ans << '\n';
}
