#include <bits/stdc++.h>
using namespace std;
const int N = 2 * 1e5 + 10;
const long long inf = 9e18 + 9;
long long res;
long long a[N];
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
void solve() {
  int h, w;
  cin >> h >> w;
  string s[h];
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }
  vector<pair<int, int>> pt;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '.') {
        pt.push_back({i, j});
      }
    }
  }
  int dist[h + 1][w + 1];
  int vist[h + 1][w + 1];
  queue<pair<int, int>> q;
  int max_all = 0;
  for (auto i : pt) {
    q.push({i.first, i.second});
    memset(dist, INT_MAX, sizeof dist);
    memset(vist, 0, sizeof vist);
    vist[i.first][i.second] = 1;
    dist[i.first][i.second] = 0;
    int max_now = 0;
    while (!q.empty()) {
      pair<int, int> p = q.front();
      q.pop();
      int newx = p.first;
      int newy = p.second;
      for (int k = 0; k < 4; k++) {
        int x = newx + dx[k];
        int y = newy + dy[k];
        if (x >= 0 && x < w && y >= 0 && y < h && vist[x][y] == 0 &&
            s[x][y] == '.') {
          q.push({x, y});
          dist[x][y] = dist[newx][newy] + 1;
          vist[x][y] = 1;
          max_now = max(max_now, dist[x][y]);
        }
      }
    }
    max_all = max(max_all, max_now);
  }
  cout << max_all << "\n";
}
int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
