#include <bits/stdc++.h>
using namespace std;
const int64_t inf = 1LL << 60;
template <class T>
inline void chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
}
template <class T>
inline void chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
}
vector<int64_t> dy = {0, 1, 0, -1};
vector<int64_t> dx = {1, 0, -1, 0};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int64_t H, W;
  cin >> H >> W;
  vector<string> S(H);
  for (int64_t i = 0; i < H; i++) {
    cin >> S[i];
  }
  int64_t ans = 0;
  for (int64_t i = 0; i < H; i++) {
    for (int64_t j = 0; j < W; j++) {
      vector<vector<int64_t>> d(H, vector<int64_t>(W, inf));
      d[i][j] = 0;
      queue<pair<int64_t, int64_t>> q;
      q.push({i, j});
      while (!q.empty()) {
        auto e = q.front();
        q.pop();
        int64_t y = e.first;
        int64_t x = e.second;
        for (int64_t i = 0; i < 4; i++) {
          int64_t ny = y + dy[i];
          int64_t nx = x + dx[i];
          if (0 <= ny && ny < H && 0 <= nx && nx < W && d[ny][nx] == inf) {
            if (S[ny][nx] == '#')
              d[ny][nx] = -1;
            else {
              d[ny][nx] = d[y][x] + 1;
              q.push({ny, nx});
            }
          }
        }
      }
      int64_t tmp = 0;
      for (int64_t k = 0; k < H; k++) {
        for (int64_t l = 0; l < W; l++) {
          chmax(tmp, d[k][l]);
        }
      }
      chmax(ans, tmp);
    }
  }
  cout << ans << endl;
}
