#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int ans = 0;
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> matrix;
  for (int i = 0; i < h; i++) {
    string s;
    cin >> s;
    matrix.push_back(s);
  }
  int ans = 0;
  queue<pair<int, pair<int, int>>> q;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      vector<vector<bool>> path(h, vector<bool>(w, false));
      if (matrix[i][j] == '.') {
        q.push({i, {j, 0}});
      }
      while (!q.empty()) {
        int x = q.front().first;
        int y = q.front().second.first;
        int l = q.front().second.second;
        q.pop();
        if (path[x][y] == true)
          continue;
        else
          path[x][y] = true;
        if (x > 0 && matrix[x][y] == '.') q.push({x - 1, {y, l + 1}});
        if (x < h - 1 && matrix[x][y] == '.') q.push({x + 1, {y, l + 1}});
        if (y > 0 && matrix[x][y] == '.') q.push({x, {y - 1, l + 1}});
        if (y < w - 1 && matrix[x][y] == '.') q.push({x, {y + 1, l + 1}});
        ans = max(ans, l);
      }
    }
  }
  cout << ans << endl;
}
