#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  char c[21][21];
  int check[21][21];
  int i, j;
  queue<pair<int, int>> que;
  cin >> H >> W;
  int ans = 0;
  for (i = 0; i < H; i++)
    for (j = 0; j < W; j++) cin >> c[i][j];
  for (i = 0; i < H; i++)
    for (j = 0; j < W; j++) {
      if (c[i][j] == '#')
        continue;
      else {
        for (int k = 0; k < H; k++)
          for (int l = 0; l < W; l++) check[k][l] = -1e9;
        check[i][j] = 0;
        que.push(pair<int, int>(i, j));
        while (!que.empty()) {
          int x = que.front().first;
          int y = que.front().second;
          int dx[4] = {1, -1, 0, 0};
          int dy[4] = {0, 0, 1, -1};
          que.pop();
          for (int k = 0; k < 4; k++) {
            if (c[x + dx[k]][y + dy[k]] == '.' &&
                check[x + dx[k]][y + dy[k]] < check[x][y] + 1) {
              check[x + dx[k]][y + dy[k]] = check[x][y] + 1;
              que.push(pair<int, int>(x + dx[k], y + dy[k]));
            }
          }
        }
        for (int k = 0; k < H; k++)
          for (int l = 0; l < W; l++)
            if (check[k][l] > ans) ans = check[k][l];
      }
    }
  cout << ans << endl;
}
