#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<int> graph[21];
int h, w;
int bfs(int i) {
  queue<int> que;
  vector<bool> flag(400, false);
  vector<int> dis(400, 1e9);
  dis[i] = 0;
  que.push(i);
  int M = 0;
  while (!que.empty()) {
    int v = que.front();
    que.pop();
    if (flag[v]) continue;
    flag[v] = true;
    for (auto e : graph[v]) {
      dis[e] = dis[e] > dis[v] + 1 ? dis[v] + 1 : dis[e];
      M = M > dis[e] ? M : dis[e];
      if (!flag[e]) que.push(e);
    }
  }
  return M;
}
int main() {
  cin >> h >> w;
  vector<string> str(h);
  for (int(i) = (0); (i) < (h); (i)++) {
    cin >> str[i];
  }
  int u, v;
  for (int(i) = (0); (i) < (h); (i)++) {
    for (int(j) = (0); (j) < (w); (j)++) {
      if (str[i][j] == '.') {
        u = i * w + j;
        if (i < h) {
          if (str[i + 1][j] == '.') {
            v = (i + 1) * w + j;
            graph[u].push_back(v);
            graph[v].push_back(u);
          }
        }
        if (j < w) {
          if (str[i][j + 1] == '.') {
            v = i * w + j + 1;
            graph[u].push_back(v);
            graph[v].push_back(u);
          }
        }
      }
    }
  }
  int ans = 0;
  for (int(i) = (0); (i) < (h); (i)++) {
    for (int(j) = (0); (j) < (w); (j)++) {
      int num = i * w + j;
      ans = ans > bfs(num) ? ans : bfs(num);
    }
  }
  cout << ans << endl;
  return 0;
}
