#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int dx[] = {0, -1, 0, 1};
int dy[] = {-1, 0, 1, 0};
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w;
  cin >> h >> w;
  vector<string> maze(h + 2);
  vector<vector<int>> a1(h + 2, vector<int>(w + 2, -1));
  ;
  vector<vector<int>> a2(h + 2, vector<int>(w + 2, -1));
  ;
  for (int i = 0; i < h; i++) {
    string str;
    cin >> str;
    maze[i + 1] = '#' + str + '#';
  }
  for (int i = 0; i < w + 2; i++) {
    maze[0] += '#';
    maze[h + 1] += '#';
  }
  pair<int, int> start;
  for (int i = 0; i < h + 2; i++)
    for (int j = 0; j < w + 2; j++) {
      if (maze[i][j] == '.') {
        start = make_pair(i, j);
        break;
      }
    }
  queue<pair<int, int>> q;
  q.push(make_pair(start.first, start.second));
  a1[start.first][start.second] = 0;
  int longest = 0;
  while (!q.empty()) {
    int x = q.front().first;
    int y = q.front().second;
    q.pop();
    if (longest < a1[x][y]) {
      longest = a1[x][y];
      start = make_pair(x, y);
    }
    for (int i = 0; i < 4; i++) {
      int hx = x + dx[i];
      int hy = y + dy[i];
      if (maze[hx][hy] == '.' && a1[hx][hy] == -1) {
        q.push(make_pair(hx, hy));
        a1[hx][hy] = a1[x][y] + 1;
      }
    }
  }
  q.push(make_pair(start.first, start.second));
  a2[start.first][start.second] = 0;
  longest = 0;
  while (!q.empty()) {
    int x = q.front().first;
    int y = q.front().second;
    q.pop();
    if (longest < a2[x][y]) {
      longest = a2[x][y];
    }
    for (int i = 0; i < 4; i++) {
      int hx = x + dx[i];
      int hy = y + dy[i];
      if (maze[hx][hy] == '.' && a2[hx][hy] == -1) {
        q.push(make_pair(hx, hy));
        a2[hx][hy] = a2[x][y] + 1;
      }
    }
  }
  cout << longest << endl;
  return 0;
}
