#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<LL, LL>;
using VI = vector<int>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VVI = vector<VI>;
const LL LINF = 1001002003004005006ll;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
void solve() {
  int H, W;
  cin >> H >> W;
  VVI A;
  for (int y = 0; y < (H); ++y) {
    string S;
    cin >> S;
    VI row;
    for (int x = 0; x < (W); ++x) {
      char c = S[x];
      if (c == '.') {
        row.push_back(1);
      } else {
        row.push_back(0);
      }
    }
    A.push_back(row);
  }
  cerr << A[0].size() << endl;
  int ans = 0;
  int N;
  N = W * H;
  VI level;
  for (int x = 0; x < (W); ++x) {
    for (int y = 0; y < (H); ++y) {
      cerr << "x=" << x << " y=" << y << endl;
      VI level;
      for (int i = 0; i < (N); ++i) level.push_back(-1);
      int start = x + W * y;
      queue<int> que;
      level[start] = 0;
      que.push(start);
      while (!que.empty()) {
        int base = que.front();
        que.pop();
        int base_x = base % W;
        int base_y = base / W;
        for (int d = 0; d < (4); ++d) {
          cerr << d << endl;
          int cand_x = base_x + dx[d];
          int cand_y = base_y + dy[d];
          int cand_id = cand_x + W * cand_y;
          if (0 <= cand_x && cand_x < W && 0 <= cand_y && cand_y < H) {
            cerr << "cand_id=" << cand_id << endl;
            if (level[cand_id] < 0 && A[cand_y][cand_x]) {
              level[cand_id] = level[base] + 1;
              que.push(cand_id);
            }
          }
        }
      }
      for (int i = 0; i < (N); ++i) {
        chmax(ans, level[i]);
      }
    }
  }
  cout << ans << endl;
  return;
}
int main() {
  int T = 1;
  for (int i = 0; i < T; ++i) {
    solve();
  }
  return 0;
}
