#include <bits/stdc++.h>
using namespace std;
pair<int, int> operator+(const pair<int, int> &lhs, const pair<int, int> &rhs) {
  return {lhs.first + rhs.first, lhs.second + rhs.second};
}
bool operator==(const pair<int, int> &lhs, const pair<int, int> &rhs) {
  return (lhs.first == rhs.first) && (lhs.second == rhs.second);
}
const pair<int, int> dir[] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
int BFS(int H, int W, vector<vector<char>> S, pair<int, int> start,
        pair<int, int> goal) {
  vector<vector<char>> memo(H + 2, vector<char>(W + 2, 0));
  queue<pair<int, int>> q;
  q.push(start);
  while (!q.empty()) {
    pair<int, int> now = q.front();
    q.pop();
    if (now == goal) return memo[now.first][now.second];
    for (int i = 0; i < 4; i++) {
      pair<int, int> next = now + dir[i];
      if (S[next.first][next.second] == '.' &&
          memo[next.first][next.second] == 0) {
        q.push(next);
        memo[next.first][next.second] = memo[now.first][now.second] + 1;
      }
    }
  }
  return -1;
}
void solve() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> S(H + 2, vector<char>(W + 2, '#'));
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) cin >> S[i][j];
  }
  int ans = 0;
  for (int sx = 1; sx <= H; sx++) {
    for (int sy = 1; sy <= W; sy++) {
      for (int gx = 1; gx <= H; gx++) {
        for (int gy = 1; gy <= W; gy++) {
          if (S[sx][sy] == '.' && S[gx][gy] == '.') {
            ans = max(ans, BFS(H, W, S, {sx, sy}, {gx, gy}));
          }
        }
      }
    }
  }
  cout << ans;
}
int main() {
  solve();
  return 0;
}
