#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
int h, w;
vector<vector<bool>> maze(21, vector<bool>(21, false));
vector<vector<int>> d(21, vector<int>(21, 1000000007));
vector<vector<int>> in = d;
int bfs(int sy, int sx, int gy, int gx) {
  queue<P> que;
  que.push(P(sx, sy));
  d = in;
  d[sy][sx] = 0;
  while (!que.empty()) {
    P p = que.front();
    que.pop();
    if (p.first == gx && p.second == gy) break;
    for (int i = 0; i < 4; i++) {
      int nx = p.first + dx[i], ny = p.second + dy[i];
      if (nx >= 0 && nx < w && ny >= 0 && ny < h && maze[ny][nx] &&
          d[ny][nx] == 1000000007) {
        que.push(P(nx, ny));
        d[ny][nx] = d[p.second][p.first] + 1;
      }
    }
  }
  return d[gy][gx];
}
int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      char c;
      cin >> c;
      if (c == '.') maze[i][j] = true;
    }
  }
  int ans = -1;
  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++) {
          int x = bfs(i, j, k, l);
          if (x != 1000000007) ans = max(ans, x);
        }
      }
    }
  }
  cout << ans << endl;
}
