#include <bits/stdc++.h>
using namespace std;
bool vis[25][25];
string s[25];
int n, m, dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
queue<pair<pair<int, int>, int> > Q;
int bfs(int i, int j) {
  for (int i = 0; i < 25; ++i)
    for (int j = 0; j < 25; ++j) vis[i][j] = 0;
  int mx = 0;
  while (!Q.empty()) Q.pop();
  Q.push(pair<pair<int, int>, int>{make_pair(i, j), 0});
  vis[i][j] = 1;
  while (!Q.empty()) {
    pair<pair<int, int>, int> tmp = Q.front();
    Q.pop();
    int cx = tmp.first.first;
    int cy = tmp.first.second;
    mx = max(mx, tmp.second);
    for (int _ = 0; _ < 4; ++_) {
      int x = cx + dx[_];
      int y = cy + dy[_];
      if (x > 0 && x <= n && y > 0 && y <= m && !vis[x][y] && s[x][y] == '.') {
        vis[x][y] = 1;
        Q.push(pair<pair<int, int>, int>{make_pair(x, y), tmp.second + 1});
      }
    }
  }
  return mx;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int ans = 0;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    s[i] = "#";
    string t;
    cin >> t;
    s[i] += t;
  }
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) {
      ans = max(ans, bfs(i, j));
    }
  cout << ans << '\n';
  return 0;
}
