#include <bits/stdc++.h>
using namespace std;
inline void solve() {
  int n, m;
  cin >> n >> m;
  vector<vector<char>> g(n, vector<char>(m));
  for (int i = 0; i < (n); i++)
    for (int j = 0; j < (m); j++) {
      cin >> g[i][j];
    }
  int otv = 0;
  for (int i = 0; i < (n); i++) {
    for (int j = 0; j < (m); j++) {
      for (int k = 0; k < (n); k++) {
        for (int h = 0; h < (m); h++) {
          if (g[i][j] != '#' && g[k][h] != '#') {
            vector<vector<bool>> used(n, vector<bool>(m, 0));
            queue<pair<pair<int, int>, int>> q;
            q.push({{i, j}, 0});
            while (q.size()) {
              pair<pair<int, int>, int> v = q.front();
              q.pop();
              used[v.first.first][v.first.second] = 1;
              if (v.first.first < 0 || v.first.first >= n ||
                  v.first.second < 0 || v.first.second >= m ||
                  used[v.first.first][v.first.second] ||
                  g[v.first.first][v.first.second] == '#') {
                continue;
              }
              if (v.first.first == k && v.first.second == h) {
                otv = max(otv, v.second);
                break;
              }
              q.push({{v.first.first + 1, v.first.second}, v.second + 1});
              q.push({{v.first.first - 1, v.first.second}, v.second + 1});
              q.push({{v.first.first, v.first.second + 1}, v.second + 1});
              q.push({{v.first.first, v.first.second - 1}, v.second + 1});
            }
          }
        }
      }
    }
  }
  cout << otv;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  solve();
}
