#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long IINF = 1e18;
const double EPS = 1e-8;
const double pi = acos(-1);
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;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H, W;
  cin >> H >> W;
  vector<string> f(H);
  for (long long i = 0; i < (H); ++i) cin >> f[i];
  int dh[4] = {1, 0, -1, 0};
  int dw[4] = {0, 1, 0, -1};
  int ans = 0;
  for (long long i = 0; i < (H); ++i) {
    for (long long j = 0; j < (W); ++j) {
      vector<vector<int>> d(H, vector<int>(W, -1));
      queue<pair<int, int>> que;
      que.push({i, j});
      d[i][j] = 0;
      while (!que.empty()) {
        pair<int, int> p = que.front();
        que.pop();
        int h = p.first, w = p.second;
        for (long long k = 0; k < (4); ++k) {
          int nh = h + dh[k], nw = w + dw[k];
          if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
          if (f[nh][nw] == '#') continue;
          if (d[nh][nw] >= 0) continue;
          d[nh][nw] = d[h][w] + 1;
          chmax(ans, d[nh][nw]);
          que.push({nh, nw});
        }
      }
    }
  }
  cout << ans << endl;
}
