#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pii = pair<int, int>;
template <typename T>
using Vec = vector<T>;
template <typename T>
bool in_range(T x, T lb, T ub) {
  return lb <= x && x < ub;
}
template <typename T>
bool in_range(T x, T y, T lb, T ub) {
  return in_range(x, lb, ub) && in_range(y, lb, ub);
}
template <typename T>
void modAdd(T& a, T b, T mod) {
  a = (a + b + mod) % mod;
}
template <typename T>
void modMul(T& a, T b, T mod) {
  a = (a * b) % mod;
}
template <typename T>
void minUpdate(T& a, T b) {
  a = min(a, b);
}
template <typename T>
void maxUpdate(T& a, T b) {
  a = max(a, b);
}
int bitCount(int x) { return __builtin_popcount(x); }
int bitCount(lint x) { return __builtin_popcountll(x); }
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1},
          Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
const double EPS = 1e-9;
const double PI = acos(-1);
int H, W;
string G[22];
int solve_maze(int sx, int sy, int gx, int gy) {
  Vec<Vec<int>> cnt(H, Vec<int>(W, -1));
  cnt[sy][sx] = 0;
  queue<pii> que;
  que.push(pii(sx, sy));
  while (!que.empty()) {
    pii p = que.front();
    que.pop();
    int x = p.first, y = p.second;
    if (x == gx and y == gy) break;
    for (int d = 0; d < 4; ++d) {
      int nx = x + dx[d];
      int ny = y + dy[d];
      if (!in_range(nx, 0, W)) continue;
      if (!in_range(ny, 0, H)) continue;
      if (G[ny][nx] == '#') continue;
      if (cnt[ny][nx] == -1) {
        cnt[ny][nx] = cnt[y][x] + 1;
        que.push(pii(nx, ny));
      }
    }
  }
  return cnt[gy][gx];
}
int main() {
  cin >> H >> W;
  for (int i = 0; i < H; ++i) cin >> G[i];
  int ans = 0;
  for (int sy = 0; sy < H; ++sy)
    for (int sx = 0; sx < W; ++sx) {
      for (int gy = 0; gy < H; ++gy)
        for (int gx = 0; gx < W; ++gx) {
          if (G[sy][sx] != '#' and G[gx][gy] != '#')
            ans = max(ans, solve_maze(sx, sy, gx, gy));
        }
    }
  cout << ans << endl;
}
