#include <bits/stdc++.h>
using namespace std;
using VP = vector<pair<long long, long long> >;
using VVP = vector<VP>;
using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
const int inf = 1e9 + 7;
const long long INF = 1LL << 61;
const long long mod = 1e9 + 7;
int h, w;
VVI s(25, VI(25, 0));
VVI v;
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
bool val(int i, int j) {
  if (i >= 0 && i < h && j >= 0 && j < w && s[i][j] == 0) return 1;
  return 0;
}
int main() {
  int i, j;
  cin >> h >> w;
  int ans = 0;
  for (i = 0; i < h; i++) {
    for (j = 0; j < w; j++) {
      char c;
      cin >> c;
      if (c == '#') s[i][j] = 1;
    }
  }
  for (i = 0; i < h; i++) {
    for (j = 0; j < w; j++) {
      v = VVI(25, VI(25, -1));
      v[i][j] = 0;
      queue<pair<long long, long long> > q;
      q.push(pair<long long, long long>(i, j));
      while (!q.empty()) {
        int x = q.front().first;
        int y = q.front().second;
        q.pop();
        for (int k = 0; k < 4; k++) {
          if (val(x + dx[k], y + dy[k]) && v[x + dx[k]][y + dy[k]] == -1) {
            q.push(pair<long long, long long>(x + dx[k], y + dy[k]));
            v[x + dx[k]][y + dy[k]] = v[x][y] + 1;
            ans = max(ans, v[x][y] + 1);
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
