#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
const long long INF = 0x3f3f3f3f3f3f3f3f;
const long long llinf = (1LL << 62);
const int inf = (1 << 30);
const int nmax = 1e5 + 50;
const int mod = 1e9 + 7;
using namespace std;
int n, m, i, j, t, p, mx, viz[25][25], dx[5], dy[5];
char c[25][25];
queue<pair<pair<int, int>, int> > q;
pair<pair<int, int>, int> x;
bool ok(int x, int y) {
  if (x >= 1 && x <= n && y >= 1 && y <= m && !viz[x][y] && c[x][y] == '.')
    return 1;
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cerr.tie(0);
  cout.tie(0);
  dx[0] = 1, dy[0] = 0, dx[1] = -1, dy[1] = 0, dx[2] = 0, dy[2] = 1, dx[3] = 0,
  dy[3] = -1;
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      cin >> c[i][j];
    }
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      if (c[i][j] == '#') continue;
      for (t = 1; t <= n; t++)
        for (p = 1; p <= m; p++) viz[t][p] = 0;
      q.push(make_pair(make_pair(i, j), 0));
      viz[i][j] = 1;
      while (!q.empty()) {
        x = q.front();
        q.pop();
        mx = max(mx, x.second);
        for (t = 0; t < 4; t++) {
          if (ok(x.first.first + dx[t], x.first.second + dy[t])) {
            q.push(make_pair(
                make_pair(x.first.first + dx[t], x.first.second + dy[t]),
                x.second + 1));
            viz[x.first.first + dx[t]][x.first.second + dy[t]] = 1;
          }
        }
      }
    }
  }
  cout << mx << endl;
  return 0;
}
