#include <bits/stdc++.h>
using ll = long long;
using namespace std;
struct Corr {
  int y;
  int x;
  int length;
};
vector<int> dy = {0, 0, -1, 1};
vector<int> dx = {-1, 1, 0, 0};
int bfs(vector<vector<char>> s, queue<Corr> q, int h, int w) {
  int y, x, length = 0, max_length = 0;
  while (!q.empty()) {
    Corr now = q.front();
    q.pop();
    y = now.y;
    x = now.x;
    length = now.length;
    for (int i = 0; i < 4; i++) {
      Corr next = {y + dy[i], x + dx[i], length + 1};
      if (0 <= next.y && next.y < h && 0 <= next.x && next.x < w &&
          s[next.y][next.x] == '.') {
        s[next.y][next.x] = '#';
        q.push(next);
      }
    }
    max_length = max(max_length, length);
  }
  return max_length;
}
int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> s(h, vector<char>(w));
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) cin >> s[i][j];
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') continue;
      queue<Corr> q;
      Corr start = {i, j, 0};
      q.emplace(start);
      ans = max(ans, bfs(s, q, h, w));
    }
  }
  cout << ans << endl;
}
