#include <bits/stdc++.h>
using namespace std;
char a[21][21];
bool vis[21][21];
int n, m;
int X[] = {1, -1, 0, 0};
int Y[] = {0, 0, 1, -1};
bool check(int i, int j) {
  return (i >= 0 && i < n && j >= 0 && j < m && !vis[i][j] && a[i][j] != '#');
}
int BFS(int i, int j, int k, int q) {
  queue<pair<int, int> > Q;
  Q.push({i, j});
  int dis[30][30];
  for (int i = 0; i <= 20; i++) {
    for (int j = 0; j <= 20; j++) {
      dis[i][j] = 1e9;
    }
  }
  memset(vis, 0, sizeof(vis));
  dis[i][j] = 0;
  Q.push({i, j});
  while (!Q.empty()) {
    pair<int, int> x = Q.front();
    vis[x.first][x.second] = true;
    Q.pop();
    for (int i = 0; i < 4; i++) {
      if (check(X[i] + x.first, Y[i] + x.second)) {
        dis[X[i] + x.first][Y[i] + x.second] = 1 + dis[x.first][x.second];
        Q.push({X[i] + x.first, Y[i] + x.second});
      }
    }
  }
  return dis[k][q];
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cin >> a[i][j];
  }
  int Ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a[i][j] == '.') {
        for (int k = 0; k < n; k++) {
          for (int q = 0; q < m; q++) {
            if (a[k][q] == '.') {
              Ans = max(Ans, BFS(i, j, k, q));
            }
          }
        }
      }
    }
  }
  cout << Ans;
  return 0;
}
