#include <bits/stdc++.h>
using namespace std;
bool check(int i, int j, int r, int c, vector<vector<int>> &visited,
           vector<vector<char>> &v) {
  return (i >= 0 && i < r && j >= 0 && j < c && visited[i][j] == 0x3f3f3f3f &&
          v[i][j] == '.');
}
int bfs(int i, int j, int r, int c, vector<vector<char>> &v) {
  vector<vector<int>> visited(r, vector<int>(c, 0x3f3f3f3f));
  visited[i][j] = 0;
  queue<pair<long long, long long>> q;
  q.push(pair<long long, long long>(i, j));
  while (!q.empty()) {
    pair<long long, long long> x = q.front();
    q.pop();
    for (long long x_ = -1; x_ < 2; x_++) {
      for (long long y_ = -1; y_ < 2; y_++) {
        if (abs(x_ - y_) != 1) continue;
        int x_new = x.first + x_;
        int y_new = x.second + y_;
        if (check(x_new, y_new, r, c, visited, v)) {
          visited[x_new][y_new] = visited[x.first][x.second] + 1;
          q.push(pair<long long, long long>(x_new, y_new));
        }
      }
    }
  }
  int maxx = 0;
  for (long long x = 0; x < r; x++) {
    for (long long y = 0; y < c; y++) {
      if (v[x][y] == '#') continue;
      maxx = max(maxx, visited[x][y]);
    }
  }
  return maxx;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<char>> v(n, vector<char>(m));
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++) cin >> v[i][j];
  int maxx = 0;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      maxx = max(maxx, bfs(i, j, n, m, v));
    }
  }
  cout << maxx;
}
