#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using si = set<int>;
using ii = pair<int, int>;
using vii = vector<ii>;
const int inf(0x3fffffff);
const int mod(1000000007);
const double pi(acos(-1.0));
signed main() {
  {
    ios::sync_with_stdio(0);
    cin.tie(0);
  };
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < h; i++) cin >> s[i];
  int mxx = 0;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) {
      int mx = 0;
      map<ii, int> d;
      queue<ii> q;
      d[{i, j}] = 0;
      q.emplace(i, j);
      while (!q.empty()) {
        auto cur = q.front();
        int step = d[cur];
        mx = step;
        q.pop();
        for (auto& r : vii{{1, 0}, {-1, 0}, {0, 1}, {0, -1}}) {
          int x = cur.first + r.first, y = cur.second + r.second;
          if (x < 0 || y < 0 || x >= h || y >= w || s[x][y] == '#' ||
              d.count({x, y}))
            continue;
          d[{x, y}] = step + 1;
          q.emplace(x, y);
        }
      }
      mxx = max(mxx, mx);
    }
  cout << mxx;
  return 0;
}
