#include <bits/stdc++.h>
using namespace std;
constexpr long long MOD = 1000000007;
int H, W;
vector<string> S(21);
vector<vector<int>> bfs(int i, int j) {
  vector<vector<int>> res(21, vector<int>(21, -1)), C(21, vector<int>(21, 0));
  queue<pair<int, int>> Q;
  C[i][j] = 1;
  res[i][j] = 0;
  if (i - 1 >= 0 && S[i - 1][j] == '.') {
    Q.emplace(i - 1, j);
    res[i - 1][j] = 1;
  }
  if (j - 1 >= 0 && S[i][j - 1] == '.') {
    Q.emplace(i, j - 1);
    res[i][j - 1] = 1;
  }
  if (i + 1 < H && S[i + 1][j] == '.') {
    Q.emplace(i + 1, j);
    res[i + 1][j] = 1;
  }
  if (j + 1 < W && S[i][j + 1] == '.') {
    Q.emplace(i, j + 1);
    res[i][j + 1] = 1;
  }
  while (!Q.empty()) {
    int k = Q.front().first, l = Q.front().second;
    Q.pop();
    C[k][l] = 1;
    if (k - 1 >= 0 && S[k - 1][l] == '.' && !C[k - 1][l]) {
      Q.emplace(k - 1, l);
      res[k - 1][l] = res[k][l] + 1;
    }
    if (l - 1 >= 0 && S[k][l - 1] == '.' && !C[k][l - 1]) {
      Q.emplace(k, l - 1);
      res[k][l - 1] = res[k][l] + 1;
    }
    if (k + 1 < H && S[k + 1][l] == '.' && !C[k + 1][l]) {
      Q.emplace(k + 1, l);
      res[k + 1][l] = res[k][l] + 1;
    }
    if (l + 1 < W && S[k][l + 1] == '.' && !C[k][l + 1]) {
      Q.emplace(k, l + 1);
      res[k][l + 1] = res[k][l] + 1;
    }
  }
  return res;
}
int main(void) {
  cin >> H >> W;
  for (int i = 0; i < H; i++) cin >> S[i];
  int res = 0;
  for (int i = 0; i < H; i++)
    for (int j = 0; j < W; j++) {
      if (S[i][j] == '#') continue;
      vector<vector<int>> L = bfs(i, j);
      for (int k = 0; k < H; k++)
        for (int l = 0; l < W; l++) res = max(res, L[k][l]);
    }
  cout << res << endl;
  return 0;
}
