#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  int dx[4] = {1, -1, 0, 0};
  int dy[4] = {0, 0, 1, -1};
  cin >> h >> w;
  char grid[20][20];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> grid[i][j];
    }
  }
  long long ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (grid[i][j] == '#') {
        continue;
      } else {
        long long board[20][20];
        for (int ii = 0; ii < h; ii++) {
          for (int jj = 0; jj < w; jj++) {
            board[ii][jj] = -1;
          }
        }
        board[i][j] = 0;
        queue<int> queueX;
        queue<int> queueY;
        queueX.push(j);
        queueY.push(i);
        while (queueX.size() > 0) {
          int x = queueX.front();
          int y = queueY.front();
          queueX.pop();
          queueY.pop();
          for (int ii = 0; ii < 4; ii++) {
            int nextX = x + dx[ii];
            int nextY = y + dy[ii];
            if (0 <= nextX && nextX <= w && 0 <= nextY && nextY <= h &&
                board[nextY][nextX] == -1 && grid[nextY][nextX] == '.') {
              board[nextY][nextX] = board[y][x] + 1;
              queueX.push(nextX);
              queueY.push(nextY);
            }
          }
        }
        long long tmp = 0;
        for (int ii = 0; ii < h; ii++) {
          for (int jj = 0; jj < w; jj++) {
            tmp = max(tmp, board[ii][jj]);
          }
        }
        ans = max(ans, tmp);
      }
    }
  }
  cout << ans << endl;
}
