#include <bits/stdc++.h>
using namespace std;
long long pw(long long x, long long a) {
  if (a == 0) return 1;
  long long t = pw(x, a / 2);
  if (a % 2 == 0)
    return (t * t);
  else
    return (t * t * x);
}
bool prime(int x) {
  if (x < 2) return false;
  for (int i = 2; i <= sqrt(x); i++) {
    if ((x % i) == 0) return false;
  }
  return true;
}
bool vis[30][30];
char a[30][30];
int cur = 0;
int n, m;
queue<pair<pair<int, int>, int> > q;
void bfs(int x, int y) {
  if (q.empty()) return;
  int i = q.front().first.first;
  int j = q.front().first.second;
  vis[i][j] = 1;
  if (i == x && j == y) cur = min(q.front().second, cur);
  if (i < n - 1 && a[i + 1][j] == '.' && !vis[i + 1][j])
    q.push({{i + 1, j}, q.front().second + 1});
  if (i > 0 && a[i - 1][j] == '.' && !vis[i - 1][j])
    q.push({{i - 1, j}, q.front().second + 1});
  if (j < m - 1 && a[i][j + 1] == '.' && !vis[i][j + 1])
    q.push({{i, j + 1}, q.front().second + 1});
  if (j > 0 && a[i][j - 1] == '.' && !vis[i][j - 1])
    q.push({{i, j - 1}, q.front().second + 1});
  q.pop();
  bfs(x, y);
}
vector<pair<int, int> > point;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
      if (a[i][j] == '.') point.push_back({i, j});
    }
  }
  int ans = 0;
  sort(point.begin(), point.end());
  for (int i = 0; i < point.size(); i++) {
    for (int j = point.size() - 1; j > i; j--) {
      cur = 1e9;
      memset(vis, 0, sizeof vis);
      q.push({{point[i].first, point[i].second}, 0});
      bfs(point[j].first, point[j].second);
      ans = max(ans, cur);
    }
  }
  cout << ans << endl;
  return 0;
}
