#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int MAZE[20][20];
int D[20 * 20][20 * 20];
int main(void) {
  int H, W;
  cin >> H >> W;
  char c;
  for (int(i) = 0; (i) < (H); (i)++) {
    for (int(j) = 0; (j) < (W); (j)++) {
      cin >> c;
      if (c == '.')
        MAZE[i][j] = 1;
      else
        MAZE[i][j] = 0;
    }
  }
  for (int(i) = 0; (i) < (20 * 20); (i)++)
    for (int(j) = 0; (j) < (20 * 20); (j)++) D[i][j] = 1000000000;
  vector<pair<int, int>> DIFFS = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}};
  for (int(i) = 0; (i) < (H); (i)++) {
    for (int(j) = 0; (j) < (W); (j)++) {
      if (MAZE[i][j] == 0) continue;
      auto node = W * i + j;
      for (auto p : DIFFS) {
        auto ni = i + p.first;
        auto nj = j + p.second;
        if (ni < 0 || ni >= H || nj < 0 || nj >= W || MAZE[ni][nj] == 0) {
          continue;
        }
        auto next_node = W * ni + nj;
        D[node][next_node] = 1;
        D[next_node][node] = 1;
      }
    }
  }
  for (int(k) = 0; (k) < (H * W); (k)++) {
    for (int(i) = 0; (i) < (H * W); (i)++) {
      for (int(j) = 0; (j) < (H * W); (j)++) {
        D[i][j] = min(D[i][j], D[i][k] + D[k][j]);
      }
    }
  }
  int ret = 0;
  for (int(i) = 0; (i) < (H * W); (i)++) {
    for (int(j) = 0; (j) < (H * W); (j)++) {
      if ((D[i][j] != 1000000000) && (D[i][j] > ret)) {
        ret = D[i][j];
      }
    }
  }
  cout << ret << endl;
  return 0;
}
