#include <bits/stdc++.h>
using namespace std;
int h, w;
int depth = -1;
void deep(vector<string> &map, int x, int y, int i) {
  for (int dx = -1; dx <= 1; dx++) {
    for (int dy = -1; dy <= 1; dy++) {
      if (x + dx < w && x + dx >= 0 && y + dy < h && y + dy >= 0) {
        if ((dx == -1 && dy == 0) || (dx == 1 && dy == 0) ||
            (dx == 0 && dy == -1) || (dx == 0 && dy == 1)) {
          if (map.at(y).at(x) == '.') {
            depth = i;
            deep(map, x + dx, y + dy, i + 1);
          } else if (map.at(y).at(x) == '#') {
            ;
          }
        }
      }
    }
  }
}
int main() {
  cin >> h >> w;
  string mapx;
  vector<string> map(h);
  for (auto &&a : map) {
    cin >> a;
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (map.at(i).at(j) == '.') {
        depth = 0;
        deep(map, i, j, 0);
      } else if (map.at(i).at(j) == '#') {
        ;
      }
    }
  }
  cout << depth << endl;
  return 0;
}
