#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
int r, c, sy, sx, gy, gx;
char ch[55][55];
int ans[55][55], flag[55][55];
int ans2[55][55], flag2[55][55];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
queue<pair<int, int> > que;
int main() {
  cin >> r >> c;
  for (int i = (0), i_end_ = (r); i < i_end_; i++) {
    for (int j = (0), j_end_ = (c); j < j_end_; j++) {
      cin >> ch[i][j];
      if (ch[i][j] == '.') {
        sy = i + 1;
        sx = j + 1;
      }
    }
  }
  flag[sy - 1][sx - 1] = 1;
  que.push(pair<int, int>(sy - 1, sx - 1));
  while (!que.empty()) {
    pair<int, int> p = que.front();
    que.pop();
    for (int i = (0), i_end_ = (4); i < i_end_; i++) {
      int x = p.second + dx[i];
      int y = p.first + dy[i];
      if (0 <= x && x <= c && 0 <= y && y <= r && !flag[y][x] &&
          ch[y][x] == '.') {
        flag[y][x] = 1;
        ans[y][x] = ans[p.first][p.second] + 1;
        que.push(pair<int, int>(y, x));
      }
    }
  }
  int maxans = 0;
  int maxi, maxj;
  for (int i = (0), i_end_ = (r); i < i_end_; i++) {
    for (int j = (0), j_end_ = (c); j < j_end_; j++) {
      if (ans[i][j] > maxans) {
        maxans = ans[i][j];
        maxi = i;
        maxj = j;
      }
    }
  }
  sy = maxi + 1;
  sx = maxj + 1;
  flag2[sy - 1][sx - 1] = 1;
  que.push(pair<int, int>(sy - 1, sx - 1));
  while (!que.empty()) {
    pair<int, int> p = que.front();
    que.pop();
    for (int i = (0), i_end_ = (4); i < i_end_; i++) {
      int x = p.second + dx[i];
      int y = p.first + dy[i];
      if (0 <= x && x <= c && 0 <= y && y <= r && !flag2[y][x] &&
          ch[y][x] == '.') {
        flag2[y][x] = 1;
        ans2[y][x] = ans2[p.first][p.second] + 1;
        que.push(pair<int, int>(y, x));
      }
    }
  }
  for (int i = (0), i_end_ = (r); i < i_end_; i++) {
    for (int j = (0), j_end_ = (c); j < j_end_; j++) {
      if (ans2[i][j] > maxans) {
        maxans = ans2[i][j];
        maxi = i;
        maxj = j;
      }
    }
  }
  cout << maxans << "\n";
  return 0;
}
