#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using namespace std;
const ll mod = 1e9 + 7;
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll sx, sy, gx, gy;
ll d[30][30];
ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
ll h, w;
char s[30][30];
ll dfs() {
  queue<pair<ll, ll> > que;
  ll ans = -1;
  for (ll i = ll(0); i < ll(h); i++) {
    for (ll j = ll(0); j < ll(w); j++) {
      for (ll k = ll(0); k < ll(h); k++) {
        for (ll l = ll(0); l < ll(w); l++) {
          if (i != k || j != l) {
            sx = i;
            sy = j;
            gx = k;
            gy = l;
            que.push(pair<ll, ll>(sx, sy));
            for (ll i = ll(0); i < ll(h); i++) {
              for (ll j = ll(0); j < ll(w); j++) {
                d[i][j] = -1e5;
              }
            }
            d[sx][sy] = 0;
            while (que.size()) {
              pair<ll, ll> p = que.front();
              que.pop();
              for (ll t = ll(0); t < ll(4); t++) {
                ll nx = p.first + dx[t], ny = p.second + dy[t];
                if (0 <= nx && nx < h && 0 <= ny && ny < w &&
                    s[nx][ny] != '#' && d[nx][ny] == -1e5) {
                  que.push(pair<ll, ll>(nx, ny));
                  d[nx][ny] = d[p.first][p.second] + 1;
                }
              }
            }
            ans = max(ans, d[gx][gy]);
          }
        }
      }
    }
  }
  return ans;
}
int main() {
  cin >> h >> w;
  for (ll i = ll(0); i < ll(h); i++) {
    for (ll j = ll(0); j < ll(w); j++) {
      cin >> s[i][j];
    }
  }
  ll tmp = dfs();
  cout << tmp;
}
