#include <bits/stdc++.h>
using namespace std;
int h, w;
int G[21][21];
int ans = 0;
int d[21][21];
int inf = 1 << 21;
char s;
queue<pair<int, int>> q;
vector<int> vec = {0, 1, -1, 0};
vector<int> uvec = {-1, 0, 0, 1};
int bfs(int i, int j) {
  q.push(pair<int, int>(i, j));
  d[i][j] = 0;
  while (!(q.empty())) {
    pair<int, int> u = q.front();
    q.pop();
    for (int i = 0; i < vec.size(); i++) {
      if (G[vec[i] + u.first][u.second + uvec[i]] == 2)
        continue;
      else if (G[u.first + vec[i]][u.second + uvec[i]] == 1 &&
               d[vec[i] + u.first][u.second + uvec[i]] == -1 &&
               u.second + uvec[i] >= 0 && u.first + vec[i] >= 0) {
        d[u.first + vec[i]][u.second + uvec[i]] = d[u.first][u.second] + 1;
        q.push(pair<int, int>(u.first + vec[i], u.second + uvec[i]));
      }
    }
  }
  int maxcos = -1;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (d[i][j] > maxcos) {
        maxcos = d[i][j];
      }
    }
  }
  return maxcos;
}
int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> s;
      if (s == '.') {
        G[i][j] = 1;
      }
      if (s == '#') {
        G[i][j] = 2;
      }
      d[i][j] = -1;
    }
  }
  for (int i = 0; i <= h; i++) {
    for (int j = 0; j <= w; j++) {
      if (i == h || j == w) G[i][j] == 2;
    }
  }
  for (int k = 0; k < h; k++) {
    for (int l = 0; l < w; l++) {
      if (G[k][l] == 1) ans = max(bfs(2, 0), ans);
      for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
          d[i][j] = -1;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
