#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;
void fun(pair<long long int, long long int> cur,
         pair<long long int, long long int> fi, long long d) {
  if (cur == fi) {
    temp_ans = min(temp_ans, d);
    return;
  }
  mat[cur.first][cur.second] = 0;
  for (long long int i = 0; i < 4; i++) {
    long long p1 = cur.first + dx[i];
    long long p2 = cur.second + dy[i];
    if (p1 >= 0 && p1 < n && p2 >= 0 && p2 < m && mat[p1][p2] == 1)
      fun(make_pair(p1, p2), fi, d + 1);
  }
  mat[cur.first][cur.second] = 1;
  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 = -1;
  for (long long int i = 0; i < n; i++)
    for (long long int j = 0; j < m; j++)
      for (long long int i1 = 0; i1 < n; i1++)
        for (long long int j1 = 0; j1 < m; j1++)
          if (adj[i][j] == 1 && adj[i1][j1] == 1) {
            mat = adj;
            temp_ans = (long long)1e18;
            fun(make_pair(i, j), make_pair(i1, j1), 0);
            ans = max(ans, temp_ans);
          }
  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);
}
