#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const double PI = 3.1415926535897932;
const long long INF = 10000000000;
long long dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
long long bfs(long long sx, long long sy, long long gx, long long gy,
              long long h, long long w, vector<vector<string> > s) {
  long long d[25][25];
  queue<pair<long long, long long> > que;
  for (long long i = (0); i < (h); i++) {
    for (long long j = (0); j < (w); j++) {
      d[i][j] = INF;
    }
  }
  que.push(pair<long long, long long>(sx, sy));
  d[sx][sy] = 0;
  while (que.size()) {
    pair<long long, long long> p = que.front();
    que.pop();
    if (p.first == gx && p.second == gy) break;
    for (long long i = (0); i < (4); i++) {
      long long nx = p.first + dx[i], ny = p.second + dy[i];
      if (0 <= nx && nx < h && 0 <= ny && ny < w && s[nx][ny] != "#" &&
          d[nx][ny] == INF) {
        que.push(pair<long long, long long>(nx, ny));
        d[nx][ny] = d[p.first][p.second] + 1;
      }
    }
  }
  return d[gx][gy];
}
long long h, w;
long long solve() {
  cin >> h >> w;
  vector<vector<string> > s(h, vector<string>(w));
  for (long long i = (0); i < (h); i++) {
    string tmp;
    cin >> tmp;
    for (long long j = (0); j < (w); j++) {
      s[i][j] = tmp.substr(j, 1);
    }
  }
  long long ans = 0;
  for (long long i = 0; i < h / 2; i++) {
    for (long long j = (0); j < (w); j++) {
      if (s[i][j] == ".") {
        for (long long k = h / 2 - 1; k < h; k++) {
          for (long long l = (0); l < (w); l++) {
            if (s[i][j] == "." && s[k][l] == ".") {
              long long tmp = bfs(i, j, k, l, h, w, s);
              if (tmp > ans) {
                ans = tmp;
              }
            }
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
int main() {
  cout << std::fixed << std::setprecision(10);
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  long long end_solve = solve();
  return (int)end_solve;
}
