#include <bits/stdc++.h>
using namespace std;
const long long dx[] = {1, 0, -1, 0, 1, 1, -1, -1},
                dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
const long long MOD = 1e9 + 7;
template <typename T>
inline T GCD(T a, T b) {
  T c;
  while (b != 0) {
    c = a % b;
    a = b;
    b = c;
  }
  return a;
}
template <typename T>
inline T LCM(T a, T b) {
  T c = GCD(a, b);
  a /= c;
  return a * b;
}
template <typename T>
inline T nCr(T a, T b) {
  T i, r = 1;
  for (i = 1; i <= b; i++) {
    r *= (a + 1 - i);
    r /= i;
  }
  return r;
}
template <typename T>
inline T nHr(T a, T b) {
  return nCr(a + b - 1, b);
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
struct edge2 {
  long long to, cost;
};
struct edge3 {
  long long from, to, cost;
};
long long H, W;
string S[20];
inline bool inside(long long x, long long y) {
  return x >= 0 && x < H && y >= 0 && y < W;
}
long long bfs(long long sx, long long sy) {
  long long dist[20][20];
  for (long long i = 0; i < (20); ++i)
    for (long long j = 0; j < (20); ++j) dist[i][j] = -1;
  queue<pair<long long, long long> > que;
  que.push({sx, sy});
  dist[sx][sy] = 0;
  while (!que.empty()) {
    pair<long long, long long> pos = que.front();
    que.pop();
    long long nowx = pos.first, nowy = pos.second;
    for (long long i = 0; i < (4); ++i) {
      long long nx = nowx + dx[i], ny = nowy + dy[i];
      if (inside(nx, ny) and S[nx][ny] != '#' and dist[nx][ny] == -1) {
        dist[nx][ny] = dist[nowx][nowy] + 1;
        que.push({nx, ny});
      }
    }
  }
  long long res = -2000000000;
  for (long long i = 0; i < (H); ++i)
    for (long long j = 0; j < (W); ++j) {
      chmax(res, dist[i][j]);
    }
  return res;
}
signed main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> H >> W;
  for (long long i = 0; i < (H); ++i) cin >> S[i];
  long long ans = -2000000000;
  for (long long i = 0; i < (H); ++i)
    for (long long j = 0; j < (W); ++j) {
      chmax(ans, bfs(i, j));
    }
  cout << ans << '\n';
}
