#include <bits/stdc++.h>
using namespace std;
const int inf = 1e5;
int f[21][21];
int used[21][21];
int res = 0;
int n, m;
bool in(int x, int l, int r) { return (l <= x && x < r); }
void bfs(int ci, int cj) {
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) used[i][j] = f[i][j] == '#';
  int curr = 0;
  vector<pair<pair<int, int>, int> > que;
  que.push_back({{ci, cj}, 0});
  used[ci][cj] = 1;
  int head = 0, tail = 0;
  for (; head <= tail; head++) {
    for (int di = -1; di <= 1; di++)
      for (int dj = -1; dj <= 1; dj++) {
        int i = que[head].first.first;
        int j = que[head].first.second;
        if (di * dj == 0 && in(i + di, 0, n) && in(j + dj, 0, m) &&
            !used[i + di][j + dj]) {
          tail++;
          used[i + di][j + dj] = 1;
          que.push_back({{i + di, j + dj}, que[head].second + 1});
        }
      }
  }
  for (int i = 0; i < que.size(); i++) curr = max(curr, que[i].second);
  res = max(curr, res);
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < m; j++) f[i][j] = s[j];
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) bfs(i, j);
  cout << res << endl;
}
