#include <bits/stdc++.h>
using namespace std;
long long int n, m;
long long int a[100][100];
long long int ch(long long int i, long long int j, long long int fi,
                 long long int fj, set<pair<long long int, long long int>> s) {
  if (i == fi && j == fj) {
    return 0;
  }
  long long int u = 1e18;
  auto it = s.find(make_pair(i - 1, j));
  if (i > 0 && a[i - 1][j] == 1 && it == s.end()) {
    s.insert(make_pair(i - 1, j));
    u = min(u, ch(i - 1, j, fi, fj, s));
  }
  it = s.find(make_pair(i + 1, j));
  if (i < n - 1 && a[i + 1][j] == 1 && it == s.end()) {
    s.insert(make_pair(i + 1, j));
    u = min(u, ch(i + 1, j, fi, fj, s));
  }
  it = s.find(make_pair(i, j - 1));
  if (j > 0 && a[i][j - 1] == 1 && it == s.end()) {
    s.insert(make_pair(i, j - 1));
    u = min(u, ch(i, j - 1, fi, fj, s));
  }
  it = s.find(make_pair(i, j + 1));
  if (j < m - 1 && a[i][j + 1] == 1 && it == s.end()) {
    s.insert(make_pair(i, j + 1));
    u = min(u, ch(i, j + 1, fi, fj, s));
  }
  return u + 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  vector<pair<long long int, long long int>> v;
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      char x;
      cin >> x;
      if (x == '.') {
        a[i][j] = 1;
        v.push_back(make_pair(i, j));
      }
    }
  }
  long long int out = 0;
  for (long long int i = 0; i < v.size(); i++) {
    for (long long int j = i + 1; j < v.size(); j++) {
      set<pair<long long int, long long int>> s;
      s.insert(make_pair(v[i].first, v[i].second));
      long long int x = ch(v[i].first, v[i].second, v[j].first, v[j].second, s);
      if (x < 1e9) {
        out = max(out, x);
      }
    }
  }
  cout << out;
  return 0;
}
