#include <bits/stdc++.h>
using namespace std;
char mat[20][20];
int bfs(int sx, int sy, int n, int m) {
  queue<int> qx;
  queue<int> qy;
  queue<int> lv;
  qx.push(sx);
  qy.push(sy);
  lv.push(0);
  int xi[4] = {1, -1, 0, 0};
  int yi[4] = {0, 0, 1, -1};
  int ans = 0;
  bool vis[n][m];
  memset(vis, 0, sizeof(vis));
  while (qx.size() != 0) {
    int x = qx.front();
    int y = qy.front();
    int l = lv.front();
    qx.pop();
    qy.pop();
    lv.pop();
    vis[x][y] = true;
    ans = max(ans, l);
    for (int i = 0; i < 4; i++) {
      int xn = x + xi[i];
      int yn = y + yi[i];
      if (xn >= 0 && xn < n && yn >= 0 && yn < m && vis[xn][yn] == false &&
          mat[xn][yn] == '.') {
        qx.push(xn);
        qy.push(yn);
        lv.push(l + 1);
      }
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cin >> mat[i][j];
  }
  bool vis[n][m];
  memset(vis, 0, sizeof(vis));
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (mat[i][j] == '.' && !vis[i][j]) {
        ans = max(ans, bfs(i, j, n, m));
        vis[i][j] = true;
      }
    }
  }
  cout << ans;
}
