#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vin = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;
const int inf = 1e9 + 7;
const ll INF = 1e18;
template <typename T>
void chmin(T &a, T b) {
  a = min(a, b);
}
template <typename T>
void chmax(T &a, T b) {
  a = max(a, b);
}
const int dx[4] = {1, 0, 0, -1};
const int dy[4] = {0, 1, -1, 0};
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  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) {
      vector<vin> dist(h, vin(w, -1));
      queue<P> q;
      dist[i][j] = 0;
      q.push(make_pair(i, j));
      while (!q.empty()) {
        P now = q.front();
        q.pop();
        int a = now.first, b = now.second;
        for (int i = 0; i < (4); ++i) {
          int na = a + dx[i];
          int nb = b + dy[i];
          if (na < 0 || nb < 0 || na >= h || nb >= w) continue;
          if (s[na][nb] == '#') continue;
          if (dist[na][nb] != -1) continue;
          q.push(make_pair(na, nb));
          dist[na][nb] = dist[a][b] + 1;
          ans = max(ans, dist[na][nb]);
        }
      }
    }
  }
  cout << ans << endl;
}
