#include <bits/stdc++.h>
using namespace std;
long long int bfs(long long int h, long long int w, vector<vector<char>> &v,
                  long long int x, long long int y) {
  vector<vector<bool>> vis(h, vector<bool>(w, false));
  queue<pair<long long int, pair<long long int, long long int>>> q;
  q.push({0, {x, y}});
  long long int ans = 0;
  long long int xa[4] = {0, -1, 1, 0};
  long long int ya[4] = {-1, 0, 0, 1};
  while (!q.empty()) {
    long long int curr_x = q.front().second.first;
    long long int curr_y = q.front().second.second;
    long long int dist = q.front().first;
    q.pop();
    vis[curr_x][curr_y] = true;
    for (long long int i = 0; i < 4; i++) {
      x = curr_x + xa[i];
      y = curr_y + ya[i];
      if (x < h && x >= 0 && y < w && y >= 0 && v[x][y] == '.' && !vis[x][y]) {
        vis[x][y] = true;
        ans = max(dist + 1, ans);
        q.push({dist + 1, {x, y}});
      }
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int h;
  cin >> h;
  long long int w;
  cin >> w;
  vector<vector<char>> v(h, vector<char>(w));
  for (long long int i = 0; i < h; i++)
    for (long long int j = 0; j < w; j++) cin >> v[i][j];
  long long int ans = 0;
  for (long long int i = 0; i < h; i++)
    for (long long int j = 0; j < w; j++) ans = max(bfs(h, w, v, i, j), ans);
  cout << ans << '\n';
  return 0;
}
