#include <bits/stdc++.h>
using namespace std;
int D[4][2] = {{1, 0}, {0, 1}, {0, -1}, {-1, 0}};
int N, M;
bool vu[20][20];
char tab[20][20];
void reset() {
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      vu[i][j] = false;
    }
  }
}
bool dedans(int x, int y) {
  if (x < 0 || y < 0 || x >= N || y >= M) return false;
  return true;
}
int main() {
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      cin >> tab[i][j];
    }
  }
  int sol = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      if (tab[i][j] == '#') continue;
      reset();
      deque<int> enCours;
      enCours.push_back(i);
      enCours.push_back(j);
      enCours.push_back(0);
      int maxi = 0;
      while (!enCours.empty()) {
        int x = enCours.front();
        enCours.pop_front();
        int y = enCours.front();
        enCours.pop_front();
        int d = enCours.front();
        enCours.pop_front();
        maxi = max(maxi, d);
        for (int k = 0; k < 4; k++) {
          int nx = x + D[k][0];
          int ny = y + D[k][1];
          if (dedans(nx, ny) && tab[nx][ny] == '.' && !vu[nx][ny]) {
            vu[nx][ny] = true;
            enCours.push_back(nx);
            enCours.push_back(ny);
            enCours.push_back(d + 1);
          }
        }
      }
      sol = max(maxi, sol);
    }
  }
  cout << sol << endl;
}
