#include <bits/stdc++.h>
using namespace std;
long long int h, w;
vector<vector<char>> grid;
vector<vector<long long int>> dist;
queue<pair<long long int, long long int>> hoge;
long long int saiki(long long int high) {
  if (hoge.empty()) {
    return high;
  }
  pair<long long int, long long int> huga = hoge.front();
  hoge.pop();
  high = max(high, dist.at(huga.first).at(huga.second));
  if (huga.first != 0 && grid.at(huga.first - 1).at(huga.second) == '.' &&
      dist.at(huga.first - 1).at(huga.second) == -1) {
    hoge.push(make_pair(huga.first - 1, huga.second));
    dist.at(huga.first - 1).at(huga.second) =
        dist.at(huga.first).at(huga.second) + 1;
  }
  if (huga.first != h - 1 && grid.at(huga.first + 1).at(huga.second) == '.' &&
      dist.at(huga.first + 1).at(huga.second) == -1) {
    hoge.push(make_pair(huga.first + 1, huga.second));
    dist.at(huga.first + 1).at(huga.second) =
        dist.at(huga.first).at(huga.second) + 1;
  }
  if (huga.second != 0 && grid.at(huga.first).at(huga.second - 1) == '.' &&
      dist.at(huga.first).at(huga.second - 1) == -1) {
    hoge.push(make_pair(huga.first, huga.second - 1));
    dist.at(huga.first).at(huga.second - 1) =
        dist.at(huga.first).at(huga.second) + 1;
  }
  if (huga.second != w - 1 && grid.at(huga.first).at(huga.second + 1) == '.' &&
      dist.at(huga.first).at(huga.second + 1) == -1) {
    hoge.push(make_pair(huga.first, huga.second + 1));
    dist.at(huga.first).at(huga.second + 1) =
        dist.at(huga.first).at(huga.second) + 1;
  }
  return saiki(high);
}
int main(void) {
  cin >> h >> w;
  grid = vector<vector<char>>(h, vector<char>(w));
  dist = vector<vector<long long int>>(h, vector<long long int>(w, -1));
  for (long long int i = 0; i < h; i++) {
    for (long long int j = 0; j < w; j++) {
      cin >> grid.at(i).at(j);
    }
  }
  long long int ans = 0;
  for (long long int i = 0; i < h; i++) {
    for (long long int j = 0; j < w; j++) {
      hoge.push(make_pair(i, j));
      dist = vector<vector<long long int>>(h, vector<long long int>(w, -1));
      dist.at(i).at(j) = 0;
      ans = max(ans, saiki(0));
    }
  }
  cout << ans << endl;
}
