#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
vector<string> maze;
int h, w;
int solve(int sx, int sy) {
  vector<vector<int>> d(h, vector<int>(w, INF));
  queue<pair<int, int>> que;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      d[i][j] = -INF;
    }
  }
  que.push(pair<int, int>(sx, sy));
  d[sx][sy] = 0;
  while (que.size()) {
    pair<int, int> p = que.front();
    que.pop();
    for (int i = 0; i < 4; i++) {
      int nx = p.first + dx[i];
      int ny = p.second + dy[i];
      if (0 <= nx && nx < h && 0 <= ny && ny < w && maze[nx][ny] != '#' &&
          d[nx][ny] == -INF) {
        que.push(pair<int, int>(nx, ny));
        d[nx][ny] = d[p.first][p.second] + 1;
      }
    }
  }
  int maxi = -INF;
  for (int i = 0; i < h; i++) {
    maxi = max(maxi, *max_element((d[i]).begin(), (d[i]).end()));
  }
  return maxi;
}
int main() {
  cin >> h >> w;
  maze.resize(h);
  for (int i = 0; i < h; i++) {
    cin >> maze[i];
  }
  int ans = -INF;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      ans = max(ans, solve(i, j));
    }
  }
  cout << ans << endl;
  return 0;
}
