#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
const long long int mod = 1000000007ll;
const long long int smod = 998244353ll;
const long long int inf = 10000000000000007ll;
const double eps = 1e-10;
struct less_key {
  bool operator()(const std::pair<long long int, long long int> &left,
                  const std::pair<long long int, long long int> &right) {
    return left.first < right.first;
  }
};
long long int gcd(long long int a, long long int b, long long int &x,
                  long long int &y) {
  if (a == 0) {
    x = 0;
    y = 1;
    return b;
  }
  long long int x1, y1;
  long long int d = gcd(b % a, a, x1, y1);
  x = y1 - (b / a) * x1;
  y = x1;
  return d;
}
long long int rev(long long int a, long long int m) {
  long long int x, y;
  long long int g = gcd(a, m, x, y);
  if (g != 1) {
    throw g;
  }
  return (x % m + m) % m;
}
long long int binpow(long long int a, long long int p) {
  if (p == 0) {
    return 1;
  }
  if (p == 1) {
    return a;
  }
  long long int t = binpow(a, p / 2);
  t *= t;
  t %= mod;
  if (p % 2) {
    t *= a;
    t %= mod;
  }
  return t;
}
const long long int MAXN = 22;
long long int h, w;
string a[MAXN];
vector<pair<long long int, long long int>> b = {
    {0, 1}, {0, -1}, {1, 0}, {-1, 0}};
long long int bfs(pair<long long int, long long int> s) {
  set<pair<long long int, long long int>> v;
  set<pair<long long int, long long int>> q;
  q.insert(s);
  v.insert(s);
  long long int max_lvl = 0;
  long long int lvl = 0;
  while (!q.empty()) {
    set<pair<long long int, long long int>> nq;
    max_lvl = max(max_lvl, lvl);
    while (!q.empty()) {
      auto c = *q.begin();
      q.erase(q.begin());
      v.insert(c);
      for (auto t : b) {
        pair<long long int, long long int> n = {c.first + t.first,
                                                c.second + t.second};
        if (n.first < 0 || n.first >= h || n.second < 0 || n.second >= w) {
          continue;
        }
        if (a[n.first][n.second] != '.') {
          continue;
        }
        if (v.count(n)) {
          continue;
        }
        nq.insert(n);
      }
    }
    q = nq;
    lvl += 1;
  }
  return max_lvl;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout.precision(15);
  cout.setf(ios::fixed);
  cin >> h >> w;
  for (long long int i = 0; i < h; i++) {
    cin >> a[i];
  }
  long long int R = 0;
  for (long long int i = 0; i < h; i++) {
    for (long long int j = 0; j < w; j++) {
      R = max(R, bfs({i, j}));
    }
  }
  cout << R << endl;
  return 0;
}
