#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;
template <typename T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
template <typename T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
template <typename T>
map<T, T> primeFactor(T n) {
  map<T, T> res;
  for (T i = 2; i * i <= n; ++i) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n] = 1;
  return res;
}
template <typename T>
bool IsPrimeNumber(T num) {
  if (num <= 2)
    return true;
  else if (num % 2 == 0)
    return false;
  double sqrtNum = sqrt(num);
  for (int i = 3; i <= sqrtNum; i += 2) {
    if (num % i == 0) {
      return false;
    }
  }
  return true;
}
long long modinv(long long a, long long m) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}
ll h, w, cntMax = 0, si, sj;
vector<vector<vector<vll>>> cntMin(
    20, vector<vector<vll>>(20, vector<vll>(20, vll(20, 999999999))));
void test(ll ssx, ll ssy, vector<string> s, ll cnt) {
  if (cntMin[si][sj][ssx][ssy] > cnt) {
    cntMin[si][sj][ssx][ssy] = cnt;
    vector<string> t = s;
    t[ssx][ssy] = '#';
    ll tmp, tmp2 = cnt;
    for (ll i = -1; i <= 1; i++) {
      for (ll j = -1; j <= 1; j++) {
        if ((i != 0 || j != 0) && (i == 0 || j == 0)) {
          if (ssx + i < h && ssx + i >= 0 && ssy + j < w && ssy + j >= 0) {
            if (t[ssx + i][ssy + j] == '.') {
              test(ssx + i, ssy + j, t, cnt + 1);
            }
          }
        }
      }
    }
  }
}
int main() {
  cin >> h >> w;
  vector<string> s;
  s.resize(h);
  for (ll i = 0; i < h; i++) {
    cin >> s[i];
  }
  for (si = 0; si < h; si++) {
    for (sj = 0; sj < w; sj++) {
      if (s[si][sj] == '.') test(si, sj, s, 0);
    }
  }
  for (ll i = 0; i < 20; i++) {
    for (ll j = 0; j < 20; j++) {
      for (ll ii = 0; ii < 20; ii++) {
        for (ll jj = 0; jj < 20; jj++) {
          if (cntMin[i][j][ii][jj] != 999999999) {
            cntMax = max(cntMax, cntMin[i][j][ii][jj]);
          }
        }
      }
    }
  }
  cout << cntMax << '\n';
  return 0;
}
