#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> s(h + 2, vector<char>(w + 2));
  int i, j;
  for (i = 0; i <= h + 1; i++) {
    for (j = 0; j <= w + 1; j++) {
      if (i == 0 || j == 0 || i == h + 1 || j == w + 1)
        s.at(i).at(j) = '#';
      else
        cin >> s.at(i).at(j);
    }
  }
  int ans = 0;
  int si, sj;
  for (si = 1; si <= h; si++) {
    for (sj = 1; sj <= w; sj++) {
      if (s.at(si).at(sj) == '#') break;
      vector<vector<int>> dist(h + 2, vector<int>(w + 2, -1));
      queue<pair<int, int>> q;
      queue<pair<int, int>> q2;
      q.push(make_pair(si, sj));
      int dis = 1;
      while (!q.empty()) {
        while (!q.empty()) {
          int nowi = q.front().first;
          int nowj = q.front().second;
          q.pop();
          if (s.at(nowi - 1).at(nowj) == '.' &&
              dist.at(nowi - 1).at(nowj) == -1) {
            q2.push(make_pair(nowi - 1, nowj));
            dist.at(nowi - 1).at(nowj) = dis;
          }
          if (s.at(nowi + 1).at(nowj) == '.' &&
              dist.at(nowi + 1).at(nowj) == -1) {
            q2.push(make_pair(nowi + 1, nowj));
            dist.at(nowi + 1).at(nowj) = dis;
          }
          if (s.at(nowi).at(nowj - 1) == '.' &&
              dist.at(nowi).at(nowj - 1) == -1) {
            q2.push(make_pair(nowi, nowj - 1));
            dist.at(nowi).at(nowj - 1) = dis;
          }
          if (s.at(nowi).at(nowj + 1) == '.' &&
              dist.at(nowi).at(nowj + 1) == -1) {
            q2.push(make_pair(nowi, nowj + 1));
            dist.at(nowi).at(nowj + 1) = dis;
          }
        }
        while (!q2.empty()) {
          q.push(q2.front());
          q2.pop();
        }
        dis++;
      }
      int dmax = 0;
      for (i = 1; i <= h; i++)
        for (j = 1; j <= w; j++)
          if (dist.at(i).at(j) > dmax) dmax = dist.at(i).at(j);
      ans = max(dmax, ans);
    }
  }
  cout << ans << endl;
}
