#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007LL;
vector<int> dx = {1, -1, 0, 0};
vector<int> dy = {0, 0, 1, -1};
int main() {
  cin.sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int h, w;
  cin >> h >> w;
  char s[h][w];
  for (int i = 0; i < h; i++) cin >> s[i];
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') continue;
      vector<vector<int> > d(h, vector<int>(w, 100005));
      d[i][j] = 0;
      int start = i * w + j;
      queue<pair<int, int> > q;
      q.push(pair<int, int>(start, 0));
      while (q.size()) {
        pair<int, int> p = q.front();
        q.pop();
        for (int l = 0; l < 4; l++) {
          int x = p.first / w + dx[l];
          int y = p.first % w + dy[l];
          if (x < 0 || x >= h) continue;
          if (y < 0 || y >= w) continue;
          if (s[x][y] == '#') continue;
          if (d[x][y] <= p.second) continue;
          d[x][y] = p.second + 1;
          q.push(pair<int, int>(x * w + y, p.second + 1));
        }
      }
      for (int k = 0; k < h; k++) {
        for (int l = 0; l < w; l++) {
          if (d[k][l] < 100005) {
            ans = max(ans, d[k][l]);
          }
        }
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
