#include <bits/stdc++.h>
using namespace std;
const long long inf = (long long)1e9;
long long H, W, ans;
char S[20][20];
long long d[20][20];
long long sx, sy, nx, ny, x, y;
long long dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
queue<pair<long long, long long> > que;
int main(void) {
  cin >> H >> W;
  for (int i = 0; i < (H); i++)
    for (int j = 0; j < (W); j++) cin >> S[i][j];
  ans = 0;
  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++) d[k][l] = inf;
      sx = i;
      sy = j;
      d[sx][sy] = 0;
      que.push(make_pair(sx, sy));
      while (!que.empty()) {
        pair<long long, long long> p = que.front();
        que.pop();
        x = p.first;
        y = p.second;
        for (int k = 0; k < (4); k++) {
          nx = x + dx[k];
          ny = y + dy[k];
          if (nx < 0 || nx >= H || ny < 0 || ny >= W || d[nx][ny] != inf ||
              S[nx][ny] == '#')
            continue;
          d[nx][ny] = d[x][y] + 1;
          que.push(make_pair(nx, ny));
        }
      }
      for (int k = 0; k < (H); k++)
        for (int l = 0; l < (W); l++)
          if (d[k][l] != inf) ans = max(ans, d[k][l]);
    }
  cout << ans << endl;
}
