#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pll = pair<ll, ll>;
using pss = pair<string, string>;
using pdd = pair<ld, ld>;
using graph = vector<vector<int>>;
using wgraph = vector<vector<pll>>;
const ll MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ex[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const int ey[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const ld E = 1e-9;
template <class T>
void chmin(T &a, T b) {
  a = min(a, b);
}
template <class T>
void chmax(T &a, T b) {
  a = max(a, b);
}
ll abs1(ll a) {
  if (a >= 0)
    return a;
  else
    return -a;
}
ll pow1(ll a, ll b, ll p = LLONG_MAX) {
  ll ret = 1;
  while (b != 0) {
    if ((b & 1) == 1) ret *= a;
    a *= a;
    if (a >= p) a %= p;
    if (ret >= p) ret %= p;
    b = b >> 1;
  }
  return ret;
}
int digit(ll a, ll b = 10) {
  int i = 0;
  while (a != 0) {
    a /= b;
    i++;
  }
  return i;
}
ll gcd1(ll a, ll b) {
  if (a == 0 || b == 0) return 0;
  ll n;
  while (a % b != 0) {
    n = a % b;
    a = b;
    b = n;
  }
  return b;
}
ll solveLinear(ll n, ll m, ll c) {
  if (n == 0 && m == 0) return 0;
  ll a[100], b[100];
  a[0] = n;
  b[0] = m;
  int i = 1;
  while (b[i - 1] != 0) {
    a[i] = b[i - 1];
    b[i] = a[i - 1] % b[i - 1];
    i++;
  }
  n = i;
  if (c % a[n - 1] != 0) return 0;
  ll x = c / a[n - 1], y = 0;
  for (i = 1; i < n; i++) {
    ll cnt = x;
    x = y;
    y = cnt - (a[n - i - 1] / b[n - i - 1]) * y;
  }
  return x;
}
ll modInv(ll a, ll p = MOD) {
  a %= p;
  ll n = solveLinear(a, p, 1);
  n %= p;
  if (n < 0) return n + p;
  return n;
}
ll fact(ll n, ll p = MOD) {
  if (n < 0) return 0;
  ll ret = 1;
  for (int i = 1; i <= n; i++) {
    ret = ret * i;
    if (ret >= p) ret %= p;
  }
  return ret;
}
ll perm(ll n, ll k, ll p = MOD) {
  if (n < 0 || k < 0 || n < k) return 0;
  ll ret = 1;
  for (ll(i) = 0; (i) < (k); (i)++) {
    ret = ret * (n - i);
    if (ret >= p) ret %= p;
  }
  return ret;
}
ll binom(ll n, ll k, ll p = MOD) {
  return (perm(n, k, p) * modInv(fact(k))) % p;
}
int bis(vector<int> v, int key) {
  int left = -1, right = v.size();
  while (abs1(right - left) > 1) {
    int mid = left + (right - left) / 2;
    if (v[mid] <= key)
      left = mid;
    else
      right = mid;
  }
  return left;
}
int main() {
  ll i, j, cnt = 0;
  int h, w;
  cin >> h >> w;
  char s[h][w];
  for (ll(i) = 0; (i) < (h); (i)++) {
    for (ll(j) = 0; (j) < (w); (j)++) {
      cin >> s[i][j];
    }
  }
  bool seen[h][w];
  ll dist[h][w];
  queue<pll> q;
  ll ans = 0;
  for (i = 0; i < h; i++) {
    for (j = 0; j < w; j++) {
      for (ll(i) = 0; (i) < (h); (i)++) {
        for (ll(j) = 0; (j) < (w); (j)++) {
          seen[i][j] = 0;
          dist[i][j] = INT_MAX;
        }
      }
      q.push({i, j});
      dist[i][j] = 0;
      while (!q.empty()) {
        int x = q.front().first, y = q.front().second;
        q.pop();
        for (int i = 0; i < 4; i++) {
          int nx = x + dx[i], ny = y + dy[i];
          if (nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
          if (s[nx][ny] == '#') continue;
          if (seen[nx][ny]) continue;
          if (dist[nx][ny] <= dist[x][y] + 1) continue;
          dist[nx][ny] = dist[x][y] + 1;
          q.push({nx, ny});
        }
      }
      for (ll(i) = 0; (i) < (h); (i)++) {
        for (ll(j) = 0; (j) < (w); (j)++) {
          if (s[i][j] == '#') continue;
          chmax(ans, dist[i][j]);
        }
      }
    }
  }
  cout << ans << endl;
}
