#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int i, j;
int h, w;
vector<vector<char>> maze;
int dy[4] = {1, -1, 0, 0}, dx[4] = {0, 0, 1, -1};
int main() {
  cin >> h >> w;
  maze.resize(h, vector<char>(w));
  for (i = 0; i < h; i++) {
    for (j = 0; j < w; j++) {
      cin >> maze[i][j];
    }
  }
  vector<vector<bool>> seen;
  vector<vector<int>> ans(h, vector<int>(w, 0));
  int maxi = 0;
  for (i = 0; i < h; i++) {
    for (j = 0; j < w; j++) {
      if (maze[i][j] == '.') {
        ans.assign(h, vector<int>(w, 0));
        queue<pair<int, int>> que;
        que.push(make_pair(i, j));
        seen.assign(h, vector<bool>(w, false));
        while (que.size() != 0) {
          pair<int, int> state = que.front();
          que.pop();
          for (int num = 0; num < 4; num++) {
            pair<int, int> next =
                make_pair(state.first + dy[num], state.second + dx[num]);
            if (next.first < 0 || next.second < 0 || next.first >= h ||
                next.second >= w)
              continue;
            if (maze[next.first][next.second] == '#') continue;
            if (seen[next.first][next.second] == true) continue;
            seen[next.first][next.second] = true;
            que.push(next);
            ans[next.first][next.second] = ans[state.first][state.second] + 1;
            maxi = max(maxi, ans[next.first][next.second]);
          }
        }
      }
    }
  }
  cout << maxi << endl;
  return 0;
}
