#include <bits/stdc++.h>
using namespace std;
int ans = INT_MIN;
int x[4] = {0, 0, 1, -1};
int y[4] = {1, -1, 0, 0};
int bfs(int i, int j, vector<vector<char>>& v, vector<vector<bool>>& vis) {
  ans = INT_MIN;
  vis[i][j] = true;
  queue<pair<int, pair<int, int>>> que;
  que.push({i, {j, 0}});
  while (que.empty() == false) {
    pair<int, pair<int, int>> one = que.front();
    vis[one.first][one.second.first] = true;
    que.pop();
    for (int k = 0; k < 4; k++) {
      int a = (one.first) - x[k], b = (one.second.first) - y[k];
      if (a > -1 && b > -1 && a < v.size() && b < v[0].size() &&
          v[a][b] != '#' && !vis[a][b]) {
        que.push({a, {b, one.second.second + 1}});
        ans = max(one.second.second + 1, ans);
      }
    }
  }
  return ans;
}
int main() {
  int n, m, a, k;
  cin >> n >> m;
  vector<vector<char>> v(n, vector<char>(m));
  vector<vector<bool>> vis(n, vector<bool>(m));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      char c;
      cin >> c;
      v[i][j] = c;
    }
  }
  int akp = INT_MIN;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (v[i][j] == '.') {
        akp = max(akp, bfs(i, j, v, vis));
        for (int i = 0; i < n; i++) {
          for (int j = 0; j < m; j++) {
            vis[i][j] = false;
          }
        }
      }
    }
  }
  cout << akp << endl;
  return 0;
}
