#include <bits/stdc++.h>
using namespace std;
int dx[] = {-1, 0, 0, 1};
int dy[] = {0, -1, 1, 0};
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h + 1);
  for (int i = 0; i < (h); i++) {
    cin >> s[i];
  }
  int ans = -1;
  for (int startH = 0; startH < (h); startH++) {
    for (int startW = 0; startW < (w); startW++) {
      queue<pair<int, int>> que;
      vector<vector<int>> dis(h, vector<int>(w, -1));
      que.push(make_pair(startH, startW));
      dis[startH][startW] = 0;
      while (!que.empty()) {
        pair<int, int> p = que.front();
        que.pop();
        for (int j = 0; j < (4); j++) {
          pair<int, int> next;
          next.first = p.first + dx[j];
          next.second = p.second + dy[j];
          if (next.first < 0 || next.first >= h || next.second < 0 ||
              next.second >= w)
            continue;
          if (s[next.first][next.second] == '#') continue;
          if (dis[next.first][next.second] != -1) continue;
          que.push(next);
          dis[next.first][next.second] = dis[p.first][p.second] + 1;
          if (dis[next.first][next.second] > ans)
            ans = dis[next.first][next.second];
        }
      }
    }
  }
  cout << ans << endl;
}
