#include <bits/stdc++.h>
using namespace std;
vector<vector<char>> theval(30, vector<char>(30, '.'));
int n, m;
int output = 0;
int hey(int a, int b, int c) {
  vector<vector<int>> visited(n + 1, vector<int>(m + 1, 0));
  queue<pair<pair<int, int>, int>> wow;
  wow.push({{a, b}, c});
  while (wow.size() > 0) {
    int start = wow.front().first.first;
    int last = wow.front().first.second;
    int val = wow.front().second;
    if (start - 1 >= 0 && theval[start - 1][last] != '#' &&
        visited[start - 1][last] == 0) {
      wow.push({{start - 1, last}, val + 1});
      output = max(output, val + 1);
      visited[start - 1][last] = 1;
    }
    if (start + 1 < n && theval[start + 1][last] &&
        visited[start + 1][last] == 0 && theval[start + 1][last] != '#') {
      wow.push({{start + 1, last}, val + 1});
      output = max(output, val + 1);
      visited[start + 1][last] = 1;
    }
    if (last - 1 >= 0 && theval[start][last - 1] != '#' &&
        visited[start][last - 1] == 0) {
      wow.push({{start, last - 1}, val + 1});
      output = max(output, val + 1);
      visited[start][last - 1] = 1;
    }
    if (last + 1 < m && theval[start][last + 1] &&
        visited[start][last + 1] == 0 && theval[start][last + 1] != '#') {
      wow.push({{start, last + 1}, val + 1});
      output = max(output, val + 1);
      visited[start][last + 1] = 1;
    }
    wow.pop();
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> theval[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      hey(i, j, 0);
    }
  }
  cout << output << endl;
}
