#include <bits/stdc++.h>
using namespace std;
int mx8[] = {0, 0, 1, -1, -1, 1, -1, 1};
int my8[] = {-1, 1, 0, 0, -1, -1, 1, 1};
int mx4[] = {1, -1, 0, 0};
int my4[] = {0, 0, -1, 1};
const int MOD = 1000000007;
int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
  int h, w;
  cin >> h >> w;
  vector<vector<char>> s(h, vector<char>(w));
  for (int i = 0; i < (h); i++)
    for (int j = 0; j < (w); j++) cin >> s[i][j];
  int ans = 0;
  const int INF = 10000;
  for (int i = 0; i < (h); i++) {
    for (int j = 0; j < (w); j++) {
      queue<pair<int, int>> q;
      q.push(pair<int, int>(i, j));
      vector<vector<int>> dist(h, vector<int>(w));
      for (int l = 0; l < (h); l++)
        for (int t = 0; t < (w); t++) dist[l][t] = INF;
      dist[i][j] = 0;
      while (!q.empty()) {
        pair<int, int> p = q.front();
        q.pop();
        int d = dist[p.first][p.second];
        for (int k = 0; k < (4); k++) {
          int y = p.first + my4[k];
          int x = p.second + mx4[k];
          if (y < 0 || y >= h || x < 0 || x >= w) continue;
          if (s[y][x] == '#') continue;
          if (dist[y][x] != 10000) continue;
          dist[y][x] = d + 1;
          ans = max(ans, d + 1);
          q.push(pair<int, int>(y, x));
        }
      }
    }
  }
  cout << ans << endl;
}
