#include <bits/stdc++.h>
using namespace std;
char c[25][25];
bool vis[25][25];
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
bool posi[25][25];
int mx = 0;
int n, m;
void bfs(int x, int y, int k, int l) {
  queue<pair<pair<int, int>, int> > q;
  q.push(make_pair(make_pair(x, y), 0));
  while (!q.empty()) {
    pair<pair<int, int>, int> pos;
    pos = q.front();
    vis[pos.first.first][pos.first.second] = 1;
    q.pop();
    if (pos.first.first == k && pos.first.second == l) {
      mx = max(mx, pos.second);
      break;
    }
    for (int i = 0; i < 4; i++) {
      int ax = pos.first.first + dx[i];
      int ay = pos.first.second + dy[i];
      if (ax >= 0 && ax < n && ay >= 0 && ay < m && !vis[ax][ay] &&
          c[ax][ay] == '.') {
        q.push(make_pair(make_pair(ax, ay), pos.second + 1));
      }
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> c[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      for (int k = 0; k < n; k++) {
        for (int l = 0; l < m; l++) {
          if (i != j && j != l && c[i][j] == '.' && c[k][l] == '.' &&
              (!posi[i][j] || !posi[k][l])) {
            memset(vis, false, sizeof(vis));
            bfs(i, j, k, l);
            posi[i][j] = 1;
            posi[j][l] = 1;
          }
        }
      }
    }
  }
  cout << mx << endl;
  return 0;
}
