#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > a;
vector<vector<int> > b;
int h, w;
void f(int i, int j, int k) {
  if (i >= 0 && j >= 0 && i < h && j < w && a[i][j] != -1 && a[i][j] > k) {
    a[i][j] = k;
    f(i, j + 1, k + 1);
    f(i + 1, j, k + 1);
    f(i, j - 1, k + 1);
    f(i - 1, j, k + 1);
  } else {
    return;
  }
}
int max_el() {
  int max_el = 0;
  for (auto v : a) {
    for (auto el : v) {
      if (max_el < el) {
        max_el = el;
      }
    }
  }
  return max_el;
}
void refresh() {
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      a[i][j] = b[i][j];
    }
  }
}
int main() {
  cin >> h >> w;
  a.assign(h, vector<int>(w, 0));
  b.assign(h, vector<int>(w, 0));
  string s;
  for (int i = 0; i < h; ++i) {
    cin >> s;
    for (int j = 0; j < w; ++j) {
      if (s[j] == '#') {
        b[i][j] = -1;
      } else {
        b[i][j] = 1e7;
      }
    }
  }
  int max_row = 0;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (a[i][j] != -1) {
        refresh();
        f(i, j, 0);
        max_row = max(max_row, max_el());
      }
    }
  }
  cout << max_row;
  return 0;
}
