#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<int>> maze(h, vector<int>(w));
  for (int i = 0; i < (h); ++i) {
    for (int j = 0; j < (w); ++j) {
      char c;
      cin >> c;
      if (c == '#') maze.at(i).at(j) = 1001001001;
    }
  }
  int ans = 0;
  vector<P> step = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}};
  for (int i = 0; i < (h); ++i) {
    for (int j = 0; j < (w); ++j) {
      if (maze.at(i).at(j) == 0) {
        queue<P> q;
        vector<vector<int>> m = maze;
        int d = 0;
        q.push({i, j});
        while (!q.empty()) {
          P now = q.front();
          q.pop();
          for (auto s : step) {
            int x = now.first + s.first;
            int y = now.second + s.second;
            if (0 <= x && x < h && 0 <= y && y < w && m.at(x).at(y) <= 1) {
              m.at(x).at(y) = m.at(now.first).at(now.second) + 1;
              d = max(d, m.at(x).at(y));
              q.push({x, y});
            }
          }
        }
        ans = max(ans, d);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
