#include <bits/stdc++.h>
template <class T>
bool maxi(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool mini(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
const ll MX = 2020, MY = 2020;
bool map2d[MX][MY];
ll depth[MX][MY];
ll dx[4] = {1, 0, 0, -1}, dy[4] = {0, 1, -1, 0};
ll bfs(ll sx, ll sy) {
  if (!map2d[sx][sy]) return 0;
  for (ll i = 0; i < MX; i++)
    for (ll j = 0; j < MY; j++) depth[i][j] = 0;
  if (depth[sx][sy]) return 0;
  deque<P> dq;
  dq.emplace_back(sx, sy);
  depth[sx][sy] = 1;
  while (!dq.empty()) {
    ll vx = dq.front().first, vy = dq.front().second;
    dq.pop_front();
    for (ll i = 0; i < 4; i++) {
      ll x = vx + dx[i], y = vy + dy[i];
      if (x < 0 or x >= MX or y < 0 or y >= MY) continue;
      if (!map2d[x][y]) continue;
      if (depth[x][y] != 0) continue;
      depth[x][y] = depth[vx][vy] + 1;
      dq.emplace_back(x, y);
    }
  }
  ll ct = 0;
  for (ll i = 0; i < MX; i++)
    for (ll j = 0; j < MY; j++) maxi(ct, depth[i][j]);
  return ct - 1;
}
void Main() {
  ll H, W;
  cin >> H >> W;
  for (ll i = 0; i < H; i++) {
    for (ll j = 0; j < W; j++) {
      char c;
      cin >> c;
      if (c == '.') map2d[i][j] = 1;
    }
  }
  ll ans = 0;
  for (ll i = 0; i < MX; i++)
    for (ll j = 0; j < MY; j++) maxi(ans, bfs(i, j));
  cout << ans << "\n";
}
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
