#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "[";
  for (auto e : v) os << e << ",";
  os << "]";
  return os;
}
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
constexpr int INF = 100000000;
constexpr long long LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;
static inline long long mod(long long x, long long m) {
  long long y = x % m;
  return (y >= 0 ? y : y + m);
}
int H, W;
char s[20][20];
int bfs(pair<int, int> start, pair<int, int> destination) {
  set<pair<int, int> > visited;
  queue<pair<pair<int, int>, int> > q;
  q.push(make_pair(start, 0));
  while (!q.empty()) {
    auto p = q.front();
    q.pop();
    if (visited.find(p.first) != visited.end()) continue;
    visited.insert(p.first);
    if (s[p.first.first][p.first.second] == '#') continue;
    if (p.first == destination) return p.second;
    for (long long i = 0ll; i < static_cast<long long>(4); i++) {
      int ni = p.first.first + dx[i];
      int nj = p.first.second + dy[i];
      if (ni < 0 || H <= ni || nj < 0 || W <= nj) continue;
      if (s[ni][nj] == '#') continue;
      pair<int, int> np = make_pair(ni, nj);
      q.emplace(np, p.second + 1);
    }
  }
  return -1;
}
void solve() {
  int ans = 0;
  for (long long si = 0ll; si < static_cast<long long>(H); si++) {
    for (long long sj = 0ll; sj < static_cast<long long>(W); sj++) {
      if (s[si][sj] == '#') continue;
      for (long long ti = 0ll; ti < static_cast<long long>(H); ti++) {
        for (long long tj = 0ll; tj < static_cast<long long>(W); tj++) {
          if (s[ti][tj] == '#') continue;
          ans = max(ans, bfs(make_pair(si, sj), make_pair(ti, tj)));
        }
      }
    }
  }
  cout << ans << endl;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> H >> W;
  for (long long i = 0ll; i < static_cast<long long>(H); i++)
    for (long long j = 0ll; j < static_cast<long long>(W); j++) cin >> s[i][j];
  solve();
  return 0;
}
