#include <bits/stdc++.h>
using namespace std;
int h, w, sx, sy, nx, ny, dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1},
                          ch[20][20], MAX;
string dp[20];
queue<pair<int, int> > que;
int main(void) {
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    cin >> dp[i];
    for (int j = 0; j < w; j++) {
      if (dp[i][j] == '.') {
        sx = i;
        sy = j;
      };
    }
  }
  que.push({sx, sy});
  ch[sx][sy] = 1;
  while (que.size()) {
    auto q = que.front();
    que.pop();
    for (int i = 0; i < 4; i++) {
      nx = q.first + dx[i];
      ny = q.second + dy[i];
      if (0 <= nx && nx < h && 0 <= ny && ny < w && dp[nx][ny] == '.') {
        if (ch[nx][ny] == 0) {
          ch[nx][ny] = ch[q.first][q.second] + 1;
          que.push({nx, ny});
        }
      }
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (ch[i][j] > MAX) {
        MAX = ch[i][j];
        sx = i;
        sy = j;
      }
    }
  }
  for (int i = 0; i < 20; i++) {
    for (int j = 0; j < 20; j++) {
      ch[i][j] = 0;
    }
  }
  que.push({sx, sy});
  ch[sx][sy] = 1;
  while (que.size()) {
    auto q = que.front();
    que.pop();
    for (int i = 0; i < 4; i++) {
      nx = q.first + dx[i];
      ny = q.second + dy[i];
      if (0 <= nx && nx < h && 0 <= ny && ny < w && dp[nx][ny] == '.') {
        if (ch[nx][ny] == 0) {
          ch[nx][ny] = ch[q.first][q.second] + 1;
          que.push({nx, ny});
        }
      }
    }
  }
  MAX = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (ch[i][j] > MAX) {
        MAX = ch[i][j];
        sx = i;
        sy = j;
      }
    }
  }
  cout << MAX - 1 << endl;
}
