#include <bits/stdc++.h>
using namespace std;
const int N = 20;
bool walls[N][N];
int h, w;
bool isValid(pair<int, int> pos) {
  return pos.first >= 0 && pos.first < h && pos.second >= 0 && pos.second < w &&
         !walls[pos.first][pos.second];
}
int bfs(pair<int, int> start) {
  int d[N][N];
  memset(d, -1, sizeof(d));
  queue<pair<int, int>> q;
  int ans = -1;
  q.push(start);
  d[start.first][start.second] = 0;
  while (!q.empty()) {
    auto t = q.front();
    q.pop();
    for (int i = t.first - 1; i <= t.first + 1; i++)
      for (int j = t.second - 1; j <= t.second + 1; j++) {
        auto p = make_pair(i, j);
        if (isValid(p) && d[i][j] == -1 && (i == t.first || j == t.second)) {
          d[i][j] = d[t.first][t.second] + 1;
          ans = max(ans, d[i][j]);
          q.push(p);
        }
      }
  }
  return ans;
}
int main() {
  cin >> h >> w;
  string s;
  int ans = -1;
  for (int i = 0; i < h; i++) {
    cin >> s;
    for (int j = 0; j < w; j++) walls[i][j] = s[j] == '#';
  }
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) ans = max(ans, bfs(make_pair(i, j)));
  cout << ans;
}
