#include <bits/stdc++.h>
using namespace std;
const int di[4] = {1, 0, -1, 0};
const int dj[4] = {0, 1, 0, -1};
int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> S(h);
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      char s;
      cin >> s;
      S[i].push_back(s);
    }
  }
  int dist_max = 0;
  for (int si = 0; si < h; ++si) {
    for (int sj = 0; sj < w; ++sj) {
      queue<pair<int, int>> Q;
      vector<vector<int>> dist(h, vector<int>(w, -1));
      dist[si][sj] = 0;
      Q.push(make_pair(si, sj));
      while (!Q.empty()) {
        int current_i = Q.front().first;
        int current_j = Q.front().second;
        Q.pop();
        for (int i = 0; i < 4; ++i) {
          int next_i = current_i + di[i];
          int next_j = current_j + dj[i];
          if (next_i < 0 || h <= next_i || next_j < 0 || w <= next_j) continue;
          if (S[next_i][next_j] == '#') continue;
          if (dist[next_i][next_j] == -1) {
            Q.push(make_pair(next_i, next_j));
            dist[next_i][next_j] = dist[current_i][current_j] + 1;
          }
        }
      }
      for (int ei = 0; ei < h; ++ei) {
        for (int ej = 0; ej < w; ++ej) {
          dist_max = max(dist[ei][ej], dist_max);
        }
      }
    }
  }
  cout << dist_max;
  return 0;
}
