#include <bits/stdc++.h>
using namespace std;
const long long INF = 2e14 + 1;
const long double PI = 3.141592;
const int MOD = 998244353;
vector<int> dx = {1, -1, 0, 0};
vector<int> dy = {0, 0, 1, -1};
bool esValido(int n, int m, int x, int y) {
  return (0 <= x && x < n && 0 <= y && y < m);
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<string> a(n);
  for (int i = 0; i < int(n); i++) cin >> a[i];
  int maxi = 0;
  for (int i = 0; i < int(n); i++) {
    for (int j = 0; j < int(n); j++) {
      if (a[i][j] == '#') continue;
      vector<vector<int>> distance(n, vector<int>(m));
      distance[i][j] = 0;
      vector<vector<bool>> visited(n, vector<bool>(m, 0));
      visited[i][j] = 1;
      queue<pair<int, int>> q;
      q.push({i, j});
      while (!q.empty()) {
        auto s = q.front();
        q.pop();
        for (int k = 0; k < int(4); k++) {
          int x = s.first + dx[k];
          int y = s.second + dy[k];
          if (esValido(n, m, x, y) && !visited[x][y] && a[x][y] != '#') {
            visited[x][y] = 1;
            distance[x][y] = distance[s.first][s.second] + 1;
            maxi = max(maxi, distance[x][y]);
            q.push({x, y});
          }
        }
      }
    }
  }
  cout << maxi << "\n";
}
