#include <bits/stdc++.h>
using namespace std;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const long long LINF = 1000000000000000000;
const long long MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline void add(T& a, T b) {
  a = ((a + b) % MOD + MOD) % MOD;
};
char fi[22][22];
int H, W;
int ans = 0;
int check(int sh, int sw, int gh, int gw) {
  long long memo[22][22];
  for (int i = 0; i < 22; i++)
    for (int j = 0; j < 22; j++) memo[i][j] = INF;
  priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>,
                 greater<tuple<int, int, int>>>
      q;
  q.emplace(0, sh, sw);
  memo[sh][sw] = 0;
  while (!q.empty()) {
    long long c;
    int h, w;
    tie(c, h, w) = q.top();
    q.pop();
    for (int i = 0; i < 4; i++) {
      int nh = h + dy[i];
      int nw = w + dx[i];
      if (!(0 <= nh && nh < H && 0 <= nw && nw < W)) continue;
      if (fi[nh][nw] == '#') continue;
      if (memo[nh][nw] > c + 1) {
        memo[nh][nw] = c + 1;
        q.emplace(c + 1, nh, nw);
      }
    }
  }
  if (memo[gh][gw] == INF) return -1;
  return memo[gh][gw];
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> H >> W;
  for (int i = 0; i < H; i++)
    for (int j = 0; j < W; j++) cin >> fi[i][j];
  for (int i = 0; i < H; i++)
    for (int j = 0; j < W; j++)
      for (int k = 0; k < H; k++)
        for (int l = 0; l < W; l++) {
          if (i == k && j == l) continue;
          if (fi[i][j] == '#' || fi[l][k] == '#') continue;
          int tmp = check(i, j, k, l);
          chmax(ans, tmp);
        }
  cout << ans << endl;
}
