#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
int INF = numeric_limits<int>::max();
int main(int, char**) {
  int h, w;
  cin >> h >> w;
  vector<vector<int>> grid(h, vector<int>(w, -1));
  int sx = -1, sy = -1;
  for (int i = 0; i < h; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < w; j++) {
      if (s[j] == '.' && sx == -1) {
        sx = i;
        sy = j;
      }
      if (s[j] == '#') grid[i][j] = INF;
    }
  }
  vector<vector<int>> grid1 = grid;
  queue<pair<int, int>> que;
  grid[sx][sy] = 0;
  int lmax = 0;
  int gx, gy;
  que.push(make_pair(sx, sy));
  vector<int> nx = {1, -1, 0, 0};
  vector<int> ny = {0, 0, 1, -1};
  while (!que.empty()) {
    pair<int, int> now = que.front();
    que.pop();
    for (int i = 0; i < 4; i++) {
      int x = now.first + nx[i];
      int y = now.second + ny[i];
      if (x < 0 || y < 0 || x > h - 1 || y > w - 1) continue;
      if (grid[x][y] == INF)
        continue;
      else if (grid[x][y] == -1) {
        grid[x][y] = grid[now.first][now.second] + 1;
        int l = grid[now.first][now.second] + 1;
        que.push(make_pair(x, y));
        if (l > lmax) {
          lmax = l;
          gx = x;
          gy = y;
        }
      }
    }
  }
  grid1[gx][gy] = 0;
  lmax = 0;
  que.push(make_pair(gx, gy));
  while (!que.empty()) {
    pair<int, int> now = que.front();
    que.pop();
    for (int i = 0; i < 4; i++) {
      int x = now.first + nx[i];
      int y = now.second + ny[i];
      if (x < 0 || y < 0 || x > h - 1 || y > w - 1) continue;
      if (grid1[x][y] == INF)
        continue;
      else if (grid1[x][y] == -1) {
        grid1[x][y] = grid1[now.first][now.second] + 1;
        int l = grid1[now.first][now.second] + 1;
        que.push(make_pair(x, y));
        if (l > lmax) {
          lmax = l;
        }
      }
    }
  }
  cout << lmax << endl;
  return 0;
}
