#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int INF = 1e9;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;
inline int add(int x, int y) {
  x += y;
  if (x >= mod) x -= mod;
  return x;
}
inline int mul(int x, int y) {
  x = (1LL * x * y) % mod;
  return x;
}
clock_t time_p = clock();
int dist[500][500];
int mat[21][21];
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
int h, w;
bool is_valid(int i, int j) {
  if (i >= 1 and i <= h and j >= 1 and j <= w and mat[i][j] == 1) return true;
  return false;
}
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  for (int i = 1; i <= 450; ++i)
    for (int j = 1; j <= 450; ++j) dist[i][j] = INF;
  for (int i = 1; i <= 450; ++i) dist[i][i] = 0;
  cin >> h >> w;
  for (int i = 1; i <= h; ++i) {
    string s;
    cin >> s;
    for (int j = 0; j <= w - 1; ++j)
      if (s[j] == '.')
        mat[i][j + 1] = 1;
      else
        mat[i][j + 1] = 0;
  }
  for (int i = 1; i <= h; ++i) {
    for (int j = 1; j <= w; ++j) {
      for (int k = 0; k <= 3; ++k) {
        int x = i + dx[k];
        int y = j + dy[k];
        if (is_valid(x, y)) {
          ;
          dist[(i - 1) * w + j][(x - 1) * w + y] = 1;
        }
      }
    }
  }
  int V = h * w;
  for (int i = 1; i <= V; ++i)
    for (int j = 1; j <= V; ++j)
      ;
  for (int k = 1; k <= V; k++) {
    for (int i = 1; i <= V; i++) {
      for (int j = 1; j <= V; j++) {
        if (dist[i][k] + dist[k][j] < dist[i][j])
          dist[i][j] = dist[i][k] + dist[k][j];
      }
    }
  }
  int ans = 0;
  for (int i = 1; i <= V; ++i) {
    for (int j = 1; j <= V; ++j) {
      ;
      if (dist[i][j] != INF) ans = max(ans, dist[i][j]);
    }
  }
  cout << ans << "\n";
  time_p = clock() - time_p;
  cerr << "\nTime Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n";
  return 0;
}
