#include <bits/stdc++.h>
using namespace std;
int H, W;
vector<vector<char> > S(21, vector<char>(21));
int bfs(int sx, int sy, int gx, int gy) {
  vector<int> dx = {-1, 0, 1, 0};
  vector<int> dy = {0, -1, 0, 1};
  vector<vector<int> > d(21, vector<int>(21));
  queue<pair<int, int> > que;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      d[i][j] = 999999;
    }
  }
  que.push(pair<int, int>(sx, sy));
  d[sx][sy] = 0;
  while (!que.empty()) {
    pair<int, int> cur = que.front();
    que.pop();
    if (cur.first == gx && cur.second == gy) break;
    for (int i = 0; i < 4; i++) {
      int nx = cur.first + dx[i], ny = cur.second + dy[i];
      if (0 <= nx && nx < H && 0 <= ny && ny < W && S[nx][ny] != '#' &&
          d[nx][ny] == 999999) {
        que.push(pair<int, int>(nx, ny));
        d[nx][ny] = d[cur.first][cur.second] + 1;
      }
    }
  }
  return d[gx][gy];
}
int main() {
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> S[i][j];
    }
  }
  int ans = 0;
  for (int sx = 0; sx < H; sx++) {
    for (int sy = 0; sy < W; sy++) {
      for (int gx = 0; gx < H; gx++) {
        for (int gy = 0; gy < W; gy++) {
          int tmp = bfs(sx, sy, gx, gy);
          if (tmp != 999999) ans = max(ans, tmp);
        }
      }
    }
  }
  cout << ans << endl;
}
