#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
const ll MOD = 1e9 + 7, N = 1e5 + 10;
string s[30];
vector<vector<ll>> dist;
vector<vector<ll>> vis;
ll h, w;
bool is_pos(ll i, ll j) {
  return i < h and j < w and i >= 0 and j >= 0 and s[i][j] == '.';
}
void dfs(ll i, ll j, ll p = 0) {
  queue<pii> q;
  q.push({i, j});
  dist[i][j] = 0;
  vis[i][j] = 1;
  while (!q.empty()) {
    pii tp = q.front();
    q.pop();
    i = tp.first;
    j = tp.second;
    if (is_pos(i + 1, j)) {
      if (!vis[i + 1][j]) {
        vis[i + 1][j] = 1;
        dist[i + 1][j] = dist[i][j] + 1;
        q.push({i + 1, j});
      }
    }
    if (is_pos(i - 1, j)) {
      if (!vis[i - 1][j]) {
        vis[i - 1][j] = 1;
        dist[i - 1][j] = dist[i][j] + 1;
        q.push({i - 1, j});
      }
    }
    if (is_pos(i, j - 1)) {
      if (!vis[i][j - 1]) {
        vis[i][j - 1] = 1;
        dist[i][j - 1] = dist[i][j] + 1;
        q.push({i, j - 1});
      }
    }
    if (is_pos(i, j + 1)) {
      if (!vis[i][j + 1]) {
        vis[i][j + 1] = 1;
        dist[i][j + 1] = dist[i][j] + 1;
        q.push({j, j + 1});
      }
    }
  }
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> h >> w;
  for (ll i = 0; i < h; i++) {
    cin >> s[i];
  }
  ll ans = 0;
  for (ll i = 0; i < h; i++) {
    for (ll j = 0; j < w; j++) {
      if (s[i][j] == '.') {
        dist = vector<vector<ll>>(h, vector<ll>(w));
        vis = dist;
        dist[i][j] = 0;
        dfs(i, j);
        for (ll k = 0; k < h; k++) {
          for (ll l = 0; l < w; l++) {
            ans = max(ans, dist[k][l]);
          }
        }
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
