#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n, m;
char arr[21][21];
bool vis[21][21];
int dis[21][21];
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int bst, idx1, idx2;
bool isValid(int i, int j) {
  return i >= 0 && i < n && j >= 0 && j < m && arr[i][j] == '.';
}
void reset() {
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      dis[i][j] = 1e9;
    }
  }
}
void bfs(int ii, int jj) {
  queue<pair<int, int>> q;
  q.emplace(ii, jj);
  dis[ii][jj] = 0;
  vis[ii][jj] = true;
  while (!q.empty()) {
    auto p = q.front();
    q.pop();
    int i = p.first, j = p.second;
    for (int k = 0; k < 4; ++k) {
      int ni = i + dx[k];
      int nj = j + dy[k];
      if (isValid(ni, nj) && dis[ni][nj] > dis[i][j] + 1) {
        dis[ni][nj] = dis[i][j] + 1;
        if (dis[ni][nj] > bst) {
          bst = dis[ni][nj];
          idx1 = ni;
          idx2 = nj;
        }
        vis[ni][nj] = true;
        q.emplace(ni, nj);
      }
    }
  }
}
int check(int i, int j) {
  reset();
  bst = 0;
  bfs(i, j);
  bst = 0;
  reset();
  bfs(idx1, idx2);
  return bst;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%s", arr[i]);
  }
  int mx = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (arr[i][j] == '.' && !vis[i][j]) {
        mx = max(mx, check(i, j));
      }
    }
  }
  printf("%d\n", mx);
  return 0;
}
