#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const int inf = (int)1e+9 + 7;
const int MAXN = 25;
char arr[MAXN][MAXN];
pair<int, int> to[4] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
vector<vector<int> > g;
int main() {
  srand(1373737);
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cin >> arr[i][j];
  }
  g.resize(n * m);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int cur = i * m + j;
      for (int t = 0; t < 4; t++) {
        int tox = i + to[t].first, toy = j + to[t].second;
        if (tox >= 0 && tox < n && toy >= 0 && toy < m && arr[tox][toy] == '.')
          g[cur].push_back(tox * m + toy);
      }
    }
  }
  int ans = -1;
  for (int i = 0; i < n * m; i++) {
    vector<int> d(n * m, inf);
    d[i] = 0;
    queue<int> q;
    q.push(i);
    while (!q.empty()) {
      int v = q.front();
      q.pop();
      for (int j = 0; j < (int)g[v].size(); j++) {
        int to = g[v][j];
        if (d[to] > d[v] + 1) {
          d[to] = d[v] + 1;
          q.push(to);
        }
      }
    }
    for (int j = 0; j < n * m; j++) {
      if (d[j] != inf) ans = max(ans, d[j]);
    }
  }
  cout << ans;
  return 0;
}
