#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", 3, "inline")
using namespace std;
int mon[20] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
long long gcd(long long x, long long y) {
  return ((y == 0) ? x : gcd(y, x % y));
}
string s[30];
int _walk[4][2] = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}};
int n, m;
long long ans, res;
bool vis[30][30];
bool check(int x, int y) {
  if (x < 0 || y < 0 || x >= n || y >= m) return 0;
  if (s[x][y] == '#' || vis[x][y] == 1) return 0;
  return 1;
}
void dfs(int x, int y, int tox, int toy, long long cnt) {
  vis[x][y] = 1;
  if (x == tox && y == toy) {
    res = min(res, cnt);
    vis[x][y] = 0;
    return;
  }
  for (int i = 0; i < 4; i++) {
    int nx, ny;
    nx = x + _walk[i][0];
    ny = y + _walk[i][1];
    if (!check(nx, ny)) continue;
    dfs(nx, ny, tox, toy, cnt + 1);
  }
  vis[x][y] = 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      for (int x = 0; x < n; x++) {
        for (int y = 0; y < m; y++) {
          if (i == x && j == y) continue;
          if (s[i][j] == '#' || s[x][y] == '#') continue;
          res = 0x7f7f7f7f;
          dfs(i, j, x, y, 0);
          ans = max(res, ans);
        }
      }
    }
  }
  cout << ans;
  return 0;
}
