#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> S(H, vector<char>(W));
  for (int i = 0; i < (H); i++) {
    for (int j = 0; j < (W); j++) {
      cin >> S.at(i).at(j);
    }
  }
  vector<int> ans(0);
  for (int m = 0; m < (H); m++) {
    for (int n = 0; n < (W); n++) {
      if (S.at(m).at(n) == '.') {
        vector<vector<int>> distance(H, vector<int>(W, -1));
        distance.at(m).at(n) == 0;
        queue<pair<int, int>> que;
        que.push({m, n});
        while (!que.empty()) {
          pair<int, int> v = que.front();
          que.pop();
          int i, j;
          i = v.first;
          j = v.second;
          if (0 <= i + 1 && i + 1 < H && 0 <= j && j < W &&
              distance.at(i + 1).at(j) == -1 && S.at(i + 1).at(j) == '.') {
            distance.at(i + 1).at(j) = distance.at(i).at(j) + 1;
            que.push({i + 1, j});
          }
          if (0 <= i - 1 && i - 1 < H && 0 <= j && j < W &&
              distance.at(i - 1).at(j) == -1 && S.at(i - 1).at(j) == '.') {
            distance.at(i - 1).at(j) = distance.at(i).at(j) + 1;
            que.push({i - 1, j});
          }
          if (0 <= i && i < H && 0 <= j + 1 && j + 1 < W &&
              distance.at(i).at(j + 1) == -1 && S.at(i).at(j + 1) == '.') {
            distance.at(i).at(j + 1) = distance.at(i).at(j) + 1;
            que.push({i, j + 1});
          }
          if (0 <= i && i < H && 0 <= j - 1 && j - 1 < W &&
              distance.at(i).at(j - 1) == -1 && S.at(i).at(j - 1) == '.') {
            distance.at(i).at(j - 1) = distance.at(i).at(j) + 1;
            que.push({i, j - 1});
          }
        }
        distance.at(m).at(n) == 0;
        for (int k = 0; k < (H); k++) {
          for (int l = 0; l < (W); l++) {
            ans.push_back(distance.at(k).at(l));
          }
        }
      }
    }
  }
  sort(ans.begin(), ans.end());
  reverse(ans.begin(), ans.end());
  cout << ans.at(0) + 1 << endl;
}
