#include <bits/stdc++.h>
using namespace std;
using ll = unsigned long long;
int main() {
  ll h, w;
  cin >> h >> w;
  vector<vector<char>> s(h + 2);
  for (ll i = 0; i < h + 2; i++) {
    vector<char> row(w + 2);
    for (ll j = 0; j < w + 2; j++) {
      if (i == 0 || i == h + 1 || j == 0 || j == w + 1) {
        row[j] = '#';
      } else {
        cin >> row[j];
      }
    }
    s[i] = row;
  }
  ll cnt = 0;
  vector<vector<int>> dirs = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
  queue<vector<ll>> q;
  for (ll i = 1; i < h + 1; i++) {
    for (ll j = 1; j < w + 1; j++) {
      for (ll k = 1; k < h + 1; k++) {
        for (ll l = 1; l < w + 1; l++) {
          if (s[k][l] == 'x') {
            s[k][l] = '.';
          }
        }
      }
      if (s[i][j] == '#') continue;
      q.push({i, j, 0});
      while (!q.empty()) {
        vector<ll> current = q.front();
        q.pop();
        for (vector<int> dir : dirs) {
          s[current[0]][current[1]] = 'x';
          ll ii = current[0] + dir[0];
          ll jj = current[1] + dir[1];
          ll depth = current[2] + 1;
          if (s[ii][jj] == '.') {
            q.push({ii, jj, depth});
            if (cnt < depth) cnt = depth;
          }
        }
      }
    }
  }
  cout << cnt << endl;
}
