#include <bits/stdc++.h>
using namespace std;
using P = pair<long long, long long>;
long long H, W;
char S[21][21];
long long func(long long dist, long long sh, long long sw, long long gh,
               long long gw, long long dir) {
  if (sh == gh && gh == gw) {
    return dist;
  } else if ((sh == gh - 1 && sw == gw) || (sh == gh + 1 && sw == gw) ||
             (sh == gh && sw == gw - 1) || (sh == gh && sw == gw + 1)) {
    return dist + 1;
  } else if (dist > H * W) {
    return dist;
  }
  long long dirH, dirW;
  dirH = gh - sh;
  dirW = gw - sw;
  long long d1 = 1000000000;
  long long d2 = 1000000000;
  long long d3 = 1000000000;
  long long d4 = 1000000000;
  long long d = 1000000000;
  if (dir != 2 && sh + 1 <= H && S[sh + 1][sw] == '.') {
    d1 = func(dist + 1, sh + 1, sw, gh, gw, 1);
  }
  if (dir != 1 && sh - 1 >= 0 && S[sh - 1][sw] == '.') {
    d2 = func(dist + 1, sh - 1, sw, gh, gw, 2);
  }
  if (dir != 4 && sw + 1 <= W && S[sh][sw + 1] == '.') {
    d3 = func(dist + 1, sh, sw + 1, gh, gw, 3);
  }
  if (dir != 3 && sw - 1 >= 0 && S[sh][sw - 1] == '.') {
    d4 = func(dist + 1, sh, sw - 1, gh, gw, 4);
  }
  d = min(d1, d2);
  d = min(d, d3);
  d = min(d, d4);
  return d;
}
long long calc(long long sh, long long sw, long long gh, long long gw) {
  long long dist = 0;
  bool map[21][21] = {{false}};
  dist = func(0, sh, sw, gh, gw, 0);
  return dist;
}
void solve_abc151() {
  long long ans;
  string tmp;
  cin >> H >> W;
  for (long long i = 0; i < (long long)(H); i++) {
    cin >> tmp;
    for (long long j = 0; j < (long long)(W); j++) {
      S[i][j] = tmp[j];
    }
  }
  ans = -1;
  for (long long sh = 0; sh < (long long)(H); sh++) {
    for (long long sw = 0; sw < (long long)(W); sw++) {
      for (long long gh = 0; gh < (long long)(H); gh++) {
        for (long long gw = 0; gw < (long long)(W); gw++) {
          if (S[sh][sw] != '#' && S[gh][gw] != '#') {
            ans = max(ans, calc(sh, sw, gh, gw));
          }
        }
      }
    }
  }
  cout << ans << "\n";
}
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve_abc151();
  return 0;
}
