#include <bits/stdc++.h>
using namespace std;
const long long N = 21;
long long n, m;
vector<vector<long long> > adj(N, vector<long long int>(N, 0));
vector<vector<long long> > mat(N, vector<long long int>(N, 0));
long long dx[] = {0, 0, 1, -1};
long long dy[] = {1, -1, 0, 0};
long long temp_ans = (long long)1e18;
vector<vector<long long> > dp(N, vector<long long int>(N, -1));
void fun(pair<long long int, long long int> curi) {
  queue<pair<pair<long long int, long long int>, long long> > q;
  q.push(make_pair(curi, 0));
  dp[curi.first][curi.second] = 0;
  while ((long long int)q.size()) {
    pair<long long int, long long int> cur = q.front().first;
    long long d = q.front().second;
    q.pop();
    mat[cur.first][cur.second] = 0;
    for (long long int i = 0; i < 4; i++) {
      long long i1 = cur.first + dx[i];
      long long j1 = cur.second + dy[i];
      if (i1 >= 0 && j1 >= 0 && i1 < n && j1 < n && mat[i1][j1] == 1 &&
          dp[i1][j1] > d + 1) {
        dp[i1][j1] = d + 1;
        q.push(make_pair(make_pair(i1, j1), d + 1));
        mat[i1][j1] = 0;
      }
    }
  }
  return;
}
int solve() {
  cin >> n >> m;
  for (long long int i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (long long int j = 0; j < m; j++)
      if (s[j] == '.')
        adj[i][j] = 1;
      else
        adj[i][j] = 0;
  }
  long long ans = 0;
  mat = adj;
  for (long long int i = 0; i < n; i++)
    for (long long int j = 0; j < m; j++)
      if (adj[i][j] == 1) {
        mat = adj;
        for (long long int i2 = 0; i2 < n; i2++)
          for (long long int j2 = 0; j2 < m; j2++) dp[i2][j2] = (long long)1e18;
        fun(make_pair(i, j));
        for (long long int i1 = 0; i1 < n; i1++)
          for (long long int j1 = 0; j1 < m; j1++) {
            if (dp[i1][j1] != (long long)1e18) ans = max(ans, dp[i1][j1]);
          }
      }
  cout << ans << "\n";
  return 0;
}
int main() {
  auto start = chrono::high_resolution_clock::now();
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long test_cases = 1;
  while (test_cases--) solve();
  auto stop = chrono::high_resolution_clock::now();
  auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start);
}
