#include <bits/stdc++.h>
using namespace std;
int n, m;
int l[] = {-1, 0, 1, 0};
int r[] = {0, -1, 0, 1};
int dfs(int i, int j, char v[][24]) {
  if (v[i][j] == '#') return 0;
  queue<pair<int, int>> q;
  int dp[n + 1][m + 1], a[n][m];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      dp[i][j] = -1;
      a[i][j] = 0;
    }
  }
  int ans = 0;
  q.push(make_pair(i, j));
  dp[i][j] = 0;
  pair<int, int> t;
  while (!q.empty()) {
    t = q.front();
    q.pop();
    a[t.first][t.second] = 1;
    for (int k = 0; k < 4; k++) {
      ;
      if ((t.first + l[k] >= 0 && t.first + l[k] < n) &&
          (t.second + r[k] >= 0 && t.second + r[k] < m)) {
        if (a[t.first + l[k]][t.second + r[k]] == 0 &&
            v[t.first + l[k]][t.second + r[k]] == '.') {
          dp[t.first + l[k]][t.second + r[k]] = dp[t.first][t.second] + 1;
          ans = max(ans, dp[t.first + l[k]][t.second + r[k]]);
          q.push(make_pair(t.first + l[k], t.second + r[k]));
        }
      }
    }
  }
  return ans;
}
int main() {
  cin >> n >> m;
  char v[24][24];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> v[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int a[25][25];
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) a[i][j] = 0;
      }
      ans = max(ans, dfs(i, j, v));
    }
  }
  cout << ans;
}
