#include <bits/stdc++.h>
int solve(const std::vector<std::string> s, const std::pair<int, int> start,
          std::pair<int, int> &farthest) {
  const int h = s.size();
  const int w = s[0].length();
  std::vector<std::vector<int>> distMap(
      h, std::vector<int>(w, std::numeric_limits<int>::max()));
  std::queue<std::pair<int, int>> q;
  distMap[start.second][start.first] = 0;
  q.push(start);
  while (q.size()) {
    const std::pair<int, int> pos = q.front();
    const int x = pos.first;
    const int y = pos.second;
    const int dist = distMap[y][x];
    q.pop();
    if (x > 0 && s[y][x - 1] == '.' && distMap[y][x - 1] > dist + 1) {
      q.push(std::pair<int, int>(x - 1, y));
      distMap[y][x - 1] = dist + 1;
    }
    if (y > 0 && s[y - 1][x] == '.' && distMap[y - 1][x] > dist + 1) {
      q.push(std::pair<int, int>(x, y - 1));
      distMap[y - 1][x] = dist + 1;
    }
    if (x < w - 1 && s[y][x + 1] == '.' && distMap[y][x + 1] > dist + 1) {
      q.push(std::pair<int, int>(x + 1, y));
      distMap[y][x + 1] = dist + 1;
    }
    if (y < h - 1 && s[y + 1][x] == '.' && distMap[y + 1][x] > dist + 1) {
      q.push(std::pair<int, int>(x, y + 1));
      distMap[y + 1][x] = dist + 1;
    }
  }
  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      if (s[y][x] == '#') {
        distMap[y][x] = -1;
      }
    }
  }
  std::pair<int, int> posFarthest = start;
  int distFarthest = 0;
  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      const int distXY = distMap[y][x];
      if (distXY > distFarthest) {
        distFarthest = distXY;
        posFarthest = std::pair<int, int>(x, y);
      }
    }
  }
  farthest = posFarthest;
  return distFarthest;
}
int main(int argc, char *argv[]) {
  int h, w;
  std::vector<std::string> s;
  std::cin >> h >> w;
  s.resize(h);
  for (int i = 0; i < h; i++) {
    std::cin >> s[i];
  }
  std::pair<int, int> initial(-1, -1);
  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      if (s[y][x] == '.') {
        initial = std::pair<int, int>(x, y);
        break;
      }
    }
    if (initial.first != -1) {
      break;
    }
  }
  std::pair<int, int> start;
  std::pair<int, int> end;
  solve(s, initial, start);
  int farthest = solve(s, start, end);
  std::cout << farthest << std::endl;
  return 0;
}
