#include <bits/stdc++.h>
using namespace std;
int H, W;
char S[20][20];
int bfs(int x, int y) {
  int col[20][20], d[20][20];
  for (int h = 0; h < H; h++) {
    for (int w = 0; w < W; w++) {
      col[w][h] = 0;
      d[w][h] = -1;
    }
  }
  queue<pair<int, int>> Q;
  if (S[x][y] == '.') {
    Q.push(make_pair(x, y));
    d[x][y] = 0;
  }
  while (!Q.empty()) {
    auto u = Q.front();
    Q.pop();
    col[u.first][u.second] = 1;
    if (u.first - 1 >= 0) {
      if (col[u.first - 1][u.second] == 0 && S[u.first - 1][u.second] == '.') {
        Q.push(make_pair(u.first - 1, u.second));
        d[u.first - 1][u.second] = d[u.first][u.second] + 1;
      }
    }
    if (u.first + 1 < W) {
      if (col[u.first + 1][u.second] == 0 && S[u.first + 1][u.second] == '.') {
        Q.push(make_pair(u.first + 1, u.second));
        d[u.first + 1][u.second] = d[u.first][u.second] + 1;
        d[u.first + 1][u.second] = d[u.first][u.second] + 1;
      }
    }
    if (u.second - 1 >= 0) {
      if (col[u.first][u.second - 1] == 0 && S[u.first][u.second - 1] == '.') {
        Q.push(make_pair(u.first, u.second - 1));
        d[u.first][u.second - 1] = d[u.first][u.second] + 1;
      }
    }
    if (u.second + 1 < H) {
      if (col[u.first][u.second + 1] == 0 && S[u.first][u.second + 1] == '.') {
        Q.push(make_pair(u.first, u.second + 1));
        d[u.first][u.second + 1] = d[u.first][u.second] + 1;
      }
    }
  }
  int ret = INT_MIN;
  for (int h = 0; h < H; h++) {
    for (int w = 0; w < W; w++) {
      ret = max(ret, d[w][h]);
    }
  }
  return ret;
}
int main() {
  cin >> H >> W;
  for (int h = 0; h < H; h++) {
    for (int w = 0; w < W; w++) {
      cin >> S[w][h];
    }
  }
  int ans = INT_MIN;
  for (int h = 0; h < H; h++) {
    for (int w = 0; w < W; w++) {
      ans = max(ans, bfs(w, h));
    }
  }
  cout << ans << endl;
  return 0;
}
