#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int h;
int w;
int bfs(vector<vector<char>> mat, int start_i, int start_j) {
  vector<vector<bool>> visited(h, vector<bool>(w));
  int level = 1;
  int last_valid = 0;
  queue<pair<int, int>> q;
  vector<pair<int, int>> dirs = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
  visited[start_i][start_j] = 0;
  q.push({start_i, start_j});
  while (!q.empty()) {
    int sz = q.size();
    for (int i = 0; i < sz; i++) {
      pair<int, int> p = q.front();
      q.pop();
      for (pair<int, int> dir : dirs) {
        int di = dir.first + p.first;
        int dj = dir.second + p.second;
        if (di >= 0 && dj >= 0 && di < h && dj < w && mat[di][dj] == '.' &&
            !visited[di][dj]) {
          last_valid = level;
          visited[di][dj] = true;
          q.push({di, dj});
        }
      }
    }
    level += 1;
  }
  return last_valid;
}
int main() {
  scanf("%d%d", &h, &w);
  vector<vector<char>> mat(h, vector<char>(w));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> mat[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (mat[i][j] == '.') {
        ans = max(ans, bfs(mat, i, j));
      }
    }
  }
  cout << ans << endl;
  return 0;
}
