#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
long long int n, m, ans = 0, dist[21][21];
char a[21][21];
bool viz[21][21];
vector<pair<long long int, long long int> > v;
int32_t main() {
  ios_base::sync_with_stdio();
  cin.tie();
  cout.tie();
  ;
  cin >> n >> m;
  for (long long int i = 0; i < n; i++)
    for (long long int j = 0; j < m; j++) {
      cin >> a[i][j];
      if (a[i][j] == '.') {
        v.push_back(make_pair(i, j));
      }
    }
  for (long long int i = 0; i < v.size(); i++)
    for (long long int j = i + 1; j < v.size(); j++) {
      queue<long long int> q1;
      queue<long long int> q2;
      q1.push(v[i].first);
      q2.push(v[i].second);
      for (long long int c = 0; c < v.size(); c++) {
        viz[v[c].first][v[c].second] = 0;
      }
      dist[v[i].first][v[i].second] = 0;
      while (!q1.empty()) {
        long long int x, y;
        x = q1.front();
        y = q2.front();
        viz[x][y] = 1;
        if (x == v[j].first && y == v[j].second) {
          break;
        }
        if (x - 1 >= 0 && a[x - 1][y] == '.' && viz[x - 1][y] == 0) {
          q1.push(x - 1);
          q2.push(y);
          dist[x - 1][y] = dist[x][y] + 1;
        }
        if (x + 1 < n && a[x + 1][y] == '.' && viz[x + 1][y] == 0) {
          q1.push(x + 1);
          q2.push(y);
          dist[x + 1][y] = dist[x][y] + 1;
        }
        if (y - 1 >= 0 && a[x][y - 1] == '.' && viz[x][y - 1] == 0) {
          q1.push(x);
          q2.push(y - 1);
          dist[x][y - 1] = dist[x][y] + 1;
        }
        if (y + 1 < m && a[x][y + 1] == '.' && viz[x][y + 1] == 0) {
          q1.push(x);
          q2.push(y + 1);
          dist[x][y + 1] = dist[x][y] + 1;
        }
        q1.pop();
        q2.pop();
      }
      ans = max(ans, dist[v[j].first][v[j].second]);
    }
  cout << ans << '\n';
}
