#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e6;
long long c0[20][20], c1[20][20][20][20];
long long dx[4] = {0, 0, 1, -1}, dy[4] = {-1, 1, 0, 0};
long long h, w;
long long bfs(long long sx, long long sy) {
  long long res = 0;
  c1[sx][sy][sx][sy] = 0;
  queue<pair<long long, long long> > que;
  que.push(pair<long long, long long>(sx, sy));
  while (!que.empty()) {
    pair<long long, long long> p = que.front();
    que.pop();
    for (long long i = 0; i < 4; ++i) {
      long long nx = p.first + dx[i], ny = p.second + dy[i];
      if (0 <= nx && h > nx && 0 <= ny && w > ny && c1[sx][sy][nx][ny] == inf) {
        que.push(pair<long long, long long>(nx, ny));
        c1[sx][sy][nx][ny] = c1[sx][sy][p.first][p.second] + 1;
        res = max(res, c1[sx][sy][nx][ny]);
      }
    }
  }
  return res;
}
int main(void) {
  cin >> h >> w;
  for (long long i = 0; i < h; ++i) {
    string s0;
    cin >> s0;
    for (long long j = 0; j < w; ++j) {
      string s1 = s0.substr(j, 1);
      if (s1 == "#") {
        c0[i][j] = -1;
      } else {
        c0[i][j] = inf;
      }
    }
  }
  long long ans = 0;
  for (long long i0 = 0; i0 < h; ++i0) {
    for (long long j0 = 0; j0 < w; ++j0) {
      for (long long i1 = 0; i1 < h; ++i1) {
        for (long long j1 = 0; j1 < w; ++j1) {
          c1[i0][j0][i1][j1] = c0[i1][j1];
        }
      }
      ans = max(bfs(i0, j0), ans);
    }
  }
  cout << ans << endl;
}
