#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int bfs2(vector<vector<int>> &arr, pair<int, int> start_coordinates, int r,
         int c) {
  queue<pair<int, int>> q;
  q.push(start_coordinates);
  while (!q.empty()) {
    pair<int, int> t = q.front();
    q.pop();
    int start_r = t.first;
    int start_c = t.second;
    if (start_r - 1 >= 0) {
      if (arr[start_r - 1][start_c] == 0 &&
          (start_r - 1 != start_coordinates.first ||
           start_c != start_coordinates.second)) {
        arr[start_r - 1][start_c] = arr[start_r][start_c] + 1;
        q.push(make_pair(start_r - 1, start_c));
      }
    }
    if (start_r + 1 < r) {
      if (arr[start_r + 1][start_c] == 0 &&
          ((start_r + 1) != start_coordinates.first ||
           start_c != start_coordinates.second)) {
        arr[start_r + 1][start_c] = arr[start_r][start_c] + 1;
        q.push(make_pair(start_r + 1, start_c));
      }
    }
    if (start_c - 1 >= 0) {
      if (arr[start_r][start_c - 1] == 0 &&
          (start_r != start_coordinates.first ||
           (start_c - 1) != start_coordinates.second)) {
        arr[start_r][start_c - 1] = arr[start_r][start_c] + 1;
        q.push(make_pair(start_r, start_c - 1));
      }
    }
    if (start_c + 1 < c) {
      if (arr[start_r][start_c + 1] == 0 &&
          (start_r != start_coordinates.first ||
           (start_c + 1) != start_coordinates.second)) {
        arr[start_r][start_c + 1] = arr[start_r][start_c] + 1;
        q.push(make_pair(start_r, start_c + 1));
      }
    }
  }
  int maxDis = 0;
  for (int i = 0; i < r; ++i) {
    for (int j = 0; j < c; ++j) {
      if (arr[i][j] == -1) {
        continue;
      }
      if (arr[i][j] > maxDis) {
        maxDis = arr[i][j];
      }
    }
  }
  return maxDis;
}
pair<int, int> bfs1(vector<vector<int>> arr, pair<int, int> start_coordinates,
                    int r, int c) {
  queue<pair<int, int>> q;
  q.push(start_coordinates);
  while (!q.empty()) {
    pair<int, int> t = q.front();
    q.pop();
    int start_r = t.first;
    int start_c = t.second;
    if (start_r - 1 >= 0) {
      if (arr[start_r - 1][start_c] == 0 &&
          (start_r - 1 != start_coordinates.first ||
           start_c != start_coordinates.second)) {
        arr[start_r - 1][start_c] = arr[start_r][start_c] + 1;
        q.push(make_pair(start_r - 1, start_c));
      }
    }
    if (start_r + 1 < r) {
      if (arr[start_r + 1][start_c] == 0 &&
          ((start_r + 1) != start_coordinates.first ||
           start_c != start_coordinates.second)) {
        arr[start_r + 1][start_c] = arr[start_r][start_c] + 1;
        q.push(make_pair(start_r + 1, start_c));
      }
    }
    if (start_c - 1 >= 0) {
      if (arr[start_r][start_c - 1] == 0 &&
          (start_r != start_coordinates.first ||
           (start_c - 1) != start_coordinates.second)) {
        arr[start_r][start_c - 1] = arr[start_r][start_c] + 1;
        q.push(make_pair(start_r, start_c - 1));
      }
    }
    if (start_c + 1 < c) {
      if (arr[start_r][start_c + 1] == 0 &&
          (start_r != start_coordinates.first ||
           (start_c + 1) != start_coordinates.second)) {
        arr[start_r][start_c + 1] = arr[start_r][start_c] + 1;
        q.push(make_pair(start_r, start_c + 1));
      }
    }
  }
  int maxDis = 0;
  int nodeIdr;
  int nodeIdc;
  for (int i = 0; i < r; ++i) {
    for (int j = 0; j < c; ++j) {
      if (arr[i][j] == -1) {
        continue;
      }
      if (arr[i][j] > maxDis) {
        maxDis = arr[i][j];
        nodeIdr = i;
        nodeIdc = j;
      }
    }
  }
  return make_pair(nodeIdr, nodeIdc);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int c, r;
  cin >> r >> c;
  char ch;
  vector<vector<int>> labyrinth(r, vector<int>(c, 0));
  int start_r, start_c;
  bool initialise = true;
  int node = 0;
  for (int i = 0; i < r; ++i) {
    for (int j = 0; j < c; ++j) {
      cin >> ch;
      if (ch == '.') {
        node++;
        if (initialise) {
          start_r = i;
          start_c = j;
          initialise = false;
        }
      } else {
        labyrinth[i][j] = -1;
      }
    }
  }
  if (node == 1) {
    cout << 0;
    return 0;
  }
  pair<int, int> start_coordinates = make_pair(start_r, start_c);
  pair<int, int> t1 = bfs1(labyrinth, start_coordinates, r, c);
  int t2 = bfs2(labyrinth, t1, r, c);
  cout << t2;
  return 0;
}
