#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int64_t>>;
const double pi = M_PI;
const int64_t MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int H, W;
vector<string> field;
int dis[21][21];
void dfs(int h, int w, int d) {
  dis[h][w] = d;
  for (int dir = 0; dir < 4; dir++) {
    int nh = h + dx[dir];
    int nw = w + dy[dir];
    if (nh < 0 || nh >= H || nw < 0 || nw >= W) {
      continue;
    }
    if (field[nh][nw] == '#') {
      continue;
    }
    if (dis[nh][nw]) {
      continue;
    }
    dfs(nh, nw, d + 1);
  }
}
int main() {
  cin >> H >> W;
  field.resize(H);
  for (int i = 0; i < H; i++) {
    cin >> field[i];
  }
  int sh1, sh2, sw1, sw2;
  for (int i = 0; i < H; i++) {
    for (int k = 0; k < W; k++) {
      if (field[i][k] == '.') {
        sh1 = i;
        sw1 = k;
        break;
      }
    }
  }
  fill(dis[0], dis[21], 0);
  dfs(sh1, sw1, 0);
  int t = 0;
  for (int i = 0; i < H; i++) {
    for (int k = 0; k < W; k++) {
      if (dis[i][k] >= t) {
        t = dis[i][k];
        sh2 = i;
        sw2 = k;
      }
    }
  }
  fill(dis[0], dis[21], 0);
  dfs(sh2, sw2, 0);
  t = 0;
  for (int i = 0; i < H; i++) {
    for (int k = 0; k < W; k++) {
      if (dis[i][k] > t) {
        t = dis[i][k];
      }
    }
  }
  cout << t << endl;
  return 0;
}
