#include <bits/stdc++.h>
using namespace std;
const long N = 3e5 + 100;
const long MOD = 1e9 + 7;
const long INF = 1e18;
int n, m;
char grid[21][21];
queue<pair<int, int> > q;
int dis[21][21];
int solve(int i, int j, int x, int y) {
  for (int ii = 1; ii <= n; ii++) {
    for (int jj = 1; jj <= m; jj++) {
      dis[ii][jj] = INT_MAX;
    }
  }
  dis[i][j] = 0;
  q.push(make_pair(i, j));
  while (!q.empty()) {
    pair<int, int> p = q.front();
    q.pop();
    vector<int> dx = {-1, 1};
    vector<int> dy = {-1, 1};
    for (int l = 0; l < 2; l++) {
      if ((p.first - dx[l]) >= 1 && (p.first - dx[l]) <= n &&
          dis[p.first - dx[l]][p.second] > (dis[p.first][p.second] + 1) &&
          grid[p.first - dx[l]][p.second] != '#') {
        dis[p.first - dx[l]][p.second] = dis[p.first][p.second] + 1;
        q.push(make_pair(p.first - dx[l], p.second));
      }
    }
    for (int l = 0; l < 2; l++) {
      if ((p.second - dy[l]) >= 1 && (p.second - dy[l]) <= m &&
          dis[p.first][p.second - dy[l]] > (dis[p.first][p.second] + 1) &&
          grid[p.first][p.second - dy[l]] != '#') {
        dis[p.first][p.second - dy[l]] = dis[p.first][p.second] + 1;
        q.push(make_pair(p.first, p.second - dy[l]));
      }
    }
  }
  if (dis[x][y] == INT_MAX)
    return -2;
  else
    return dis[x][y];
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> grid[i][j];
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      for (int x = 1; x <= n; x++) {
        for (int y = 1; y <= m; y++) {
          if (grid[i][j] == '.' && grid[x][y] == '.' && (i != x || y != j)) {
            ans = max(ans, solve(i, j, x, y));
          }
        }
      }
    }
  }
  cout << ans << endl;
}
