#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
template <class T>
ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}
int main() {
  ll h, w;
  vector<string> v;
  cin >> h >> w;
  for (ll i = 0; i < h; i++) {
    string s;
    cin >> s;
    v.push_back(s);
  }
  queue<vector<ll>> q;
  ll ans = 0;
  ll d[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
  for (ll i = 0; i < h; i++) {
    for (ll j = 0; j < w; j++) {
      if (v[i][j] == '.') {
        set<pair<ll, ll>> visited;
        vector<ll> st = {j, i, 0};
        ll m = 0;
        q.push(st);
        while (!q.empty()) {
          ll x = q.front()[0];
          ll y = q.front()[1];
          ll cost = q.front()[2];
          m = max(m, cost);
          visited.insert(make_pair(x, y));
          q.pop();
          for (ll k = 0; k < 4; k++) {
            ll nx = x + d[k][0];
            ll ny = y + d[k][1];
            if (0 <= nx and nx < w and 0 <= ny and ny < h and
                v[ny][nx] == '.' and
                visited.find(make_pair(nx, ny)) == visited.end()) {
              vector<ll> nst = {nx, ny, cost + 1};
              q.push(nst);
            }
          }
        }
        ans = max(ans, m);
      }
    }
  }
  std::cout << ans << std::endl;
  return 0;
}
