#include <bits/stdc++.h>
using namespace std;
vector<string> board;
long long h, w;
long long dx[4] = {1, 0, -1, 0};
long long dy[4] = {0, -1, 0, 1};
long long find_longest(long long sx, long long sy) {
  long long max_num = 0;
  vector<vector<long long>> costs(h, vector<long long>(w, -1));
  costs[sx][sy] = 0;
  queue<pair<pair<long long, long long>, long long>> q;
  q.push(make_pair(make_pair(sx, sy), 0));
  while (q.size()) {
    auto item = q.front();
    q.pop();
    long long x = item.first.first;
    long long y = item.first.second;
    long long cost = item.second;
    costs[y][x] = cost;
    for (long long i = 0; i < 4; i++) {
      long long nx = x + dx[i];
      long long ny = y + dy[i];
      if (0 <= nx && nx < w && 0 <= ny && ny < h && board[ny][nx] == '.' &&
          (costs[ny][nx] == -1 || costs[ny][nx] > cost + 1))
        q.push(make_pair(make_pair(nx, ny), cost + 1));
    }
  }
  for (long long i = 0; i < h; i++)
    for (long long j = 0; j < w; j++) {
      if (costs[i][j] != -1) max_num = max(max_num, costs[i][j]);
    }
  return max_num;
}
int main() {
  cin >> h >> w;
  board.resize(h);
  long long max_num = 0;
  for (long long i = 0; i < h; i++) cin >> board[i];
  for (long long i = 0; i < h; i++)
    for (long long j = 0; j < w; j++) {
      if (board[i][j] == '#') continue;
      max_num = max(max_num, find_longest(j, i));
    }
  cout << max_num << endl;
  return 0;
}
