#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int i, j, n, m, ans, h, hh, k, kk, ii, jj;
  cin >> n >> m;
  char a[n + 5][m + 5];
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  int fans = 0;
  int vis[n + 5][m + 5], lvl[n + 5][m + 5];
  queue<pair<int, int> > q;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      for (h = 0; h < n; h++) {
        for (hh = 0; hh < m; hh++) {
          vis[h][hh] = 0;
          lvl[h][hh] = 0;
        }
      }
      if (a[i][j] == '#') continue;
      q.push({i, j});
      lvl[i][j] = 0;
      while (!q.empty()) {
        pair<int, int> r = q.front();
        q.pop();
        ii = r.first;
        jj = r.second;
        for (k = -1; k < 2; k++) {
          for (kk = -1; kk < 2; kk++) {
            if ((abs(k) + abs(kk) == 1) && (ii + k < n) && (ii + k >= 0) &&
                (jj + kk >= 0) && (jj + kk < m)) {
              if (vis[ii + k][jj + kk] == 0 && a[ii + k][jj + kk] != '#') {
                q.push({ii + k, jj + kk});
                lvl[ii + k][jj + kk] = lvl[ii][jj] + 1;
                vis[ii + k][jj + kk] = 1;
              }
            }
          }
        }
      }
      int ans = 0;
      for (h = 0; h < n; h++) {
        for (hh = 0; hh < m; hh++) {
          ans = max(ans, lvl[h][hh]);
        }
      }
      fans = max(fans, ans);
    }
  }
  cout << fans;
}
