#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int dx[] = {0, -1, 0, 1};
int dy[] = {-1, 0, 1, 0};
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w;
  cin >> h >> w;
  vector<string> maze(h + 2);
  vector<vector<int>> a(h + 2, vector<int>(w + 2, -1));
  ;
  for (int i = 0; i < h; i++) {
    string str;
    cin >> str;
    maze[i + 1] = '#' + str + '#';
  }
  for (int i = 0; i < w + 2; i++) {
    maze[0] += '#';
    maze[h + 1] += '#';
  }
  pair<int, int> start;
  int ans = 0;
  for (int i = 0; i < h + 2; i++)
    for (int j = 0; j < w + 2; j++) {
      if (maze[i][j] == '.') {
        start = make_pair(i, j);
        queue<pair<int, int>> q;
        q.push(make_pair(start.first, start.second));
        int longest = 0;
        while (!q.empty()) {
          int x = q.front().first;
          int y = q.front().second;
          q.pop();
          if (longest < a[x][y]) {
            longest = a[x][y];
          }
          for (int k = 0; k < 4; k++) {
            int hx = x + dx[k];
            int hy = y + dy[k];
            if (maze[hx][hy] == '.' && a[hx][hy] == -1) {
              q.push(make_pair(hx, hy));
              a[hx][hy] = a[x][y] + 1;
            }
          }
        }
        for (int ii = 0; ii < h + 2; ii++)
          for (int jj = 0; jj < w + 2; jj++) a[ii][jj] = -1;
        ans = max(longest, ans);
      }
    }
  cout << ans << endl;
  return 0;
}
