#include <bits/stdc++.h>
using namespace std;
inline long long add(long long a, long long b) {
  return ((a % 1000000007) + (b % 1000000007)) % 1000000007;
}
inline long long mul(long long a, long long b) {
  return ((a % 1000000007) * (b % 1000000007)) % 1000000007;
}
inline long long sub(long long a, long long b) {
  return ((a % 1000000007) - (b % 1000000007) + 1000000007) % 1000000007;
}
char mat[21][21];
bool vis[21][21];
long long n, m;
bool chk(pair<long long, long long> x) {
  if (x.first == -1 || x.first == n) {
    return false;
  }
  if (x.second == -1 || x.second == m) {
    return false;
  }
  if (mat[x.first][x.second] == '#') {
    return false;
  }
  if (vis[x.first][x.second]) {
    return false;
  }
  return true;
}
long long bfs(pair<long long, long long> start,
              pair<long long, long long> end) {
  queue<pair<long long, long long> > q;
  memset(vis, false, sizeof(vis));
  q.push(start);
  long long ret = 0;
  long long si;
  pair<long long, long long> tf;
  pair<long long, long long> tin;
  while (!q.empty()) {
    si = q.size();
    for (long long i = 0; i < si; i++) {
      tf = q.front();
      q.pop();
      if (tf == end) {
        return ret;
      }
      vis[tf.first][tf.second] = true;
      tin = make_pair(tf.first - 1, tf.second);
      if (chk(tin)) {
        q.push(tin);
      }
      tin = make_pair(tf.first + 1, tf.second);
      if (chk(tin)) {
        q.push(tin);
      }
      tin = make_pair(tf.first, tf.second - 1);
      if (chk(tin)) {
        q.push(tin);
      }
      tin = make_pair(tf.first, tf.second + 1);
      if (chk(tin)) {
        q.push(tin);
      }
    }
    ++ret;
  }
}
void Flash() {
  cin >> n >> m;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      cin >> mat[i][j];
    }
  }
  long long ans = -1 * 1000000000000000000;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      for (long long ii = 0; ii < n; ii++) {
        for (long long jj = 0; jj < m; jj++) {
          if (mat[ii][jj] == '.' && mat[i][j] == '.') {
            ans = max(ans, bfs(make_pair(i, j), make_pair(ii, jj)));
          }
        }
      }
    }
  }
  cout << ans << "\n";
}
int main(int argc, char const *argv[]) {
  ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
  ;
  long long t = 1;
  for (long long i = 1; i <= t; i++) {
    Flash();
  }
  return 0;
}
