#include <bits/stdc++.h>
using namespace std;
int check[25][25];
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, -1, 1};
queue<pair<int, int> > q;
vector<vector<char> > S;
void bfs(int i, int j) {
  for (int k = 0; k < 4; k++) {
    if (check[i + dy[k]][j + dx[k]] < 0 && S[i + dy[k]][j + dx[k]] == '.') {
      check[i + dy[k]][j + dx[k]] = check[i][j] + 1;
      q.push(make_pair(i + dy[k], j + dx[k]));
    }
  }
}
int main() {
  int H, W;
  cin >> H >> W;
  S.resize(H + 2);
  for (int i = 0; i < H + 2; i++) S[i].resize(W + 2);
  for (int i = 0; i < W + 2; i++) S[0][i] = '#';
  for (int i = 1; i <= H; i++) {
    S[i][0] = '#';
    for (int j = 1; j <= W; j++) cin >> S[i][j];
    S[i][W + 1] = '#';
  }
  for (int i = 0; i < W + 2; i++) S[H + 1][i] = '#';
  int ans = -1;
  int cnt;
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      for (int k = 0; k < 25; k++) {
        for (int l = 0; l < 25; l++) {
          check[k][l] = -1;
        }
      }
      q.push(make_pair(i, j));
      check[i][j] = 0;
      while (!q.empty()) {
        bfs(q.front().first, q.front().second);
        q.pop();
      }
      cnt = 0;
      for (int k = 0; k < 25; k++) {
        for (int l = 0; l < 25; l++) {
          cnt = max(cnt, check[k][l]);
        }
      }
      ans = max(ans, cnt);
    }
  }
  cout << ans << endl;
}
