#include <bits/stdc++.h>
using namespace std;
int dfs(vector<vector<char>> &arr, int i, int j, int k, int l, int h, int w,
        vector<vector<int>> &dp) {
  if (i < 0 || j < 0 || i >= h || j >= w || arr[i][j] == '#') return -1;
  if (i == k && j == l) {
    dp[i][j] = 0;
    return 0;
  }
  if (dp[i][j] != -2) return dp[i][j];
  dp[i][j] = -1;
  int ans = INT_MAX;
  int a = dfs(arr, i + 1, j, k, l, h, w, dp);
  int b = dfs(arr, i - 1, j, k, l, h, w, dp);
  int c = dfs(arr, i, j + 1, k, l, h, w, dp);
  int d = dfs(arr, i, j - 1, k, l, h, w, dp);
  if (a != -1) ans = min(ans, a);
  if (b != -1) ans = min(ans, b);
  if (c != -1) ans = min(ans, c);
  if (d != -1) ans = min(ans, d);
  if (a == -1 && b == -1 && c == -1 && d == -1)
    dp[i][j] = -1;
  else
    dp[i][j] = ans + 1;
  return dp[i][j];
}
void solve(int test_case) {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> arr(h, vector<char>(w));
  for (auto &i : arr)
    for (auto &j : i) cin >> j;
  int sol = 0;
  for (int i = 0; i <= h - 1; i++) {
    for (int j = 0; j <= w - 1; j++) {
      for (int k = 0; k <= h - 1; k++)
        for (int l = 0; l <= w - 1; l++)
          if (arr[i][j] == '.' && arr[k][l] == '.') {
            vector<vector<int>> dp(h, vector<int>(w, -2));
            int d = dfs(arr, i, j, k, l, h, w, dp);
            if (d != -1) sol = max(d, sol);
          }
    }
  }
  cout << sol;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  for (int i = 1; i <= t; i++) {
    solve(i);
  }
  return 0;
}
