#include <bits/stdc++.h>
const long long int MOD = 1e9 + 7;
const int N = 1005;
const long long int INF = 1e9;
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  n += 2;
  m += 2;
  char g[23][23];
  for (int i = 1; i < n - 1; i++)
    for (int j = 1; j < m - 1; j++) cin >> g[i][j];
  for (int j = 0; j < m; j++) g[0][j] = '#';
  for (int j = 0; j < m; j++) g[n - 1][j] = '#';
  for (int i = 0; i < n; i++) {
    g[i][0] = '#';
    g[i][m - 1] = '#';
  }
  bool used[23][23];
  queue<pair<int, int>> q;
  int d[23][23];
  int ans = 0;
  for (int i = 1; i < n - 1; i++)
    for (int j = 1; j < m - 1; j++) {
      if (g[i][j] == '#') continue;
      for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++) {
          used[i][j] = 0;
          d[i][j] = 0;
        }
      for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
          if (g[i][j] == '#') {
            d[i][j] = 0;
            used[i][j] = 1;
          }
      used[i][j] = 1;
      d[i][j] = 0;
      q.push({i, j});
      while (!q.empty()) {
        int l = q.front().first;
        int k = q.front().second;
        q.pop();
        if (!used[l + 1][k]) {
          used[l][k] = 1;
          d[l + 1][k] = d[l][k] + 1;
          q.push({l + 1, k});
        }
        if (!used[l - 1][k]) {
          used[l][k] = 1;
          d[l - 1][k] = d[l][k] + 1;
          q.push({l - 1, k});
        }
        if (!used[l][k + 1]) {
          used[l][k] = 1;
          d[l][k + 1] = d[l][k] + 1;
          q.push({l, k + 1});
        }
        if (!used[l][k - 1]) {
          used[l][k] = 1;
          d[l][k - 1] = d[l][k] + 1;
          q.push({l, k - 1});
        }
      }
      for (int i = 1; i < n - 1; i++)
        for (int j = 1; j < m - 1; j++) ans = max(ans, d[i][j]);
    }
  cout << ans;
  return 0;
}
