#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const long long mod = 1e9 + 7;
ll gcd(ll a, ll b);
ll lcm(ll a, ll b);
vector<vector<ll>> s(23, vector<ll>(23, mod));
vector<vector<ll>> d(23, vector<ll>(23, mod));
ll cnt = 0, dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1}, h, w;
void bfs(ll a, ll b);
int main() {
  cin >> h >> w;
  char tmp;
  for (ll i = 1; i < h + 1; i++) {
    for (ll j = 1; j < w + 1; j++) {
      cin >> tmp;
      if (tmp == '.') s[i][j] = 0;
    }
  }
  for (ll i = 1; i < h + 1; i++) {
    for (ll j = 1; j < w + 1; j++) {
      bfs(i, j);
    }
  }
  cout << cnt;
  return 0;
}
void bfs(ll a, ll b) {
  queue<pair<ll, ll>> que;
  for (ll i = 0; i < 23; i++) {
    for (ll j = 0; j < 23; j++) {
      d[i][j] = mod;
    }
  }
  que.push(pair<ll, ll>(a, b));
  d[a][b] = 0;
  while (que.size()) {
    pair<ll, ll> p = que.front();
    que.pop();
    for (ll i = 0; i < 4; i++) {
      for (ll i = 0; i < 4; i++) {
        ll nx = p.first + dx[i];
        ll ny = p.second + dy[i];
        if (s[nx][ny] == 0 && d[nx][ny] == mod) {
          que.push(pair<ll, ll>(nx, ny));
          d[nx][ny] = d[p.first][p.second] + 1;
          cnt = max(cnt, d[nx][ny]);
        }
      }
    }
  }
}
ll gcd(ll a, ll b) {
  if (a % b == 0)
    return (b);
  else
    return (gcd(b, a % b));
}
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
