#include <bits/stdc++.h>
using namespace std;
const long long N = 30;
const long long mod = 1e9 + 7;
int n, m;
char a[N][N];
bool used[N][N];
int ans[N][N], mx[N][N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) cin >> a[i][j];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (a[i][j] == '#') continue;
      queue<pair<int, int> > q;
      for (int k = 1; k < N; k++) memset(used[k], 0, N), memset(ans[k], 0, N);
      q.push({i, j});
      used[i][j] = 1;
      while (!q.empty()) {
        int x = q.front().first;
        int y = q.front().second;
        q.pop();
        if (a[x][y + 1] == '.' && !used[x][y + 1]) {
          ans[x][y + 1] = ans[x][y] + 1;
          used[x][y + 1] = 1;
          mx[x][y + 1] = max(mx[x][y + 1], ans[x][y + 1]);
          q.push({x, y + 1});
        }
        if (a[x][y - 1] == '.' && !used[x][y - 1]) {
          ans[x][y - 1] = ans[x][y] + 1;
          mx[x][y - 1] = max(mx[x][y - 1], ans[x][y - 1]);
          used[x][y - 1] = 1;
          q.push({x, y - 1});
        }
        if (a[x - 1][y] == '.' && !used[x - 1][y]) {
          ans[x - 1][y] = ans[x][y] + 1;
          used[x - 1][y] = 1;
          mx[x - 1][y] = max(mx[x - 1][y], ans[x - 1][y]);
          q.push({x - 1, y});
        }
        if (a[x + 1][y] == '.' && !used[x + 1][y]) {
          ans[x + 1][y] = ans[x][y] + 1;
          used[x + 1][y] = 1;
          mx[x + 1][y] = max(mx[x + 1][y], ans[x + 1][y]);
          q.push({x + 1, y});
        }
      }
    }
  }
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      sum = max(sum, mx[i][j]);
    }
  }
  cout << sum;
}
