#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using namespace std;
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;
}
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll h, w;
  cin >> h >> w;
  vector<vector<ll>> vec(h, vector<ll>(w));
  for (int i = 0; i < (int)(h); i++) {
    string s;
    cin >> s;
    for (int j = 0; j < (int)(w); j++) {
      if (s[j] == '.') {
        vec[i][j] = 1;
      }
    }
  }
  ll res = 0;
  for (int i = 0; i < (int)(h); i++) {
    for (int j = 0; j < (int)(w); j++) {
      if (!vec[i][j]) {
        break;
      }
      vector<vector<ll>> have(h, vector<ll>(w));
      vector<vector<ll>> reg(h, vector<ll>(w, 0));
      have[i][j] = 1;
      queue<pair<ll, ll>> q;
      q.push({i, j});
      int dx[] = {-1, 0, 1, 0};
      int dy[] = {0, 1, 0, -1};
      while (!q.empty()) {
        pair<ll, ll> temp = q.front();
        q.pop();
        ll x = temp.second;
        ll y = temp.first;
        for (int f = 0; f < (int)(4); f++) {
          if (x + dx[f] >= 0 && x + dx[f] < w && y + dy[f] >= 0 &&
              y + dy[f] < h && have[y + dy[f]][x + dx[f]] == 0 &&
              vec[y + dy[f]][x + dx[f]]) {
            q.push({y + dy[f], x + dx[f]});
            have[y + dy[f]][x + dx[f]] = 1;
            reg[y + dy[f]][x + dx[f]] = reg[y][x] + 1;
          }
        }
      }
      for (int k = 0; k < (int)(h); k++) {
        for (int l = 0; l < (int)(w); l++) {
          chmax(res, reg[k][l]);
        }
      }
    }
  }
  cout << res << endl;
}
