#include <bits/stdc++.h>
using namespace std;
int H, W;
vector<pair<int, int>> a(4);
vector<vector<char>> s;
int dfs(int i, int j) {
  vector<vector<bool>> flag(H + 2, vector<bool>(W + 2, false));
  vector<vector<int>> d(H + 2, vector<int>(W + 2));
  int m = 0;
  queue<pair<int, int>> q;
  q.push(pair<int, int>(i, j));
  d[i][j] = 0;
  while (q.size() != 0) {
    pair<int, int> now = q.front();
    q.pop();
    flag[now.first][now.second] = true;
    for (int k = 0; k < (4); k++) {
      int x = now.first + a[k].first, y = now.second + a[k].second;
      if (s[x][y] == '.' && d[x][y] == 0) {
        q.push(pair<int, int>(x, y));
        d[x][y] = d[now.first][now.second] + 1;
        m = max(m, d[x][y]);
      }
    }
  }
  return m;
}
int main(void) {
  H, W;
  cin >> H >> W;
  s.resize(H + 2, vector<char>(W + 2));
  a = {pair<int, int>(0, -1), pair<int, int>(1, 0), pair<int, int>(0, 1),
       pair<int, int>(-1, 0)};
  int ans = 0;
  for (int i = 0; i < (H + 2); i++) {
    s[i][0] = s[i][W + 1] = '#';
  }
  for (int i = 0; i < (W + 2); i++) {
    s[0][i] = s[H + 1][i] = '#';
  }
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      cin >> s[i][j];
    }
  }
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      if (s[i][j] == '.') {
        ans = max(ans, dfs(i, j));
      }
    }
  }
  cout << ans << endl;
  return 0;
}
