#include <bits/stdc++.h>
using namespace std;
vector<vector<char>> table(21, vector<char>(21, '#'));
vector<vector<int>> dist(21, vector<int>(21, 0));
vector<vector<bool>> seen(21, vector<bool>(21, 0));
int h, w;
void init_seen() {
  for (int i = 1; i < h + 1; i++)
    for (int j = 1; j < w + 1; j++) seen[i][j] = 0;
}
void init_dist() {
  for (int i = 1; i < h + 1; i++)
    for (int j = 1; j < w + 1; j++) dist[i][j] = 0;
}
int main() {
  cin >> h >> w;
  for (int i = 1; i < h + 1; i++)
    for (int j = 1; j < w + 1; j++) cin >> table[i][j];
  int ans = 0;
  for (int i = 1; i < h + 1; i++) {
    for (int j = 1; j < w + 1; j++) {
      init_dist();
      init_seen();
      queue<pair<int, int>> q;
      pair<int, int> p = make_pair(i, j);
      q.push(p);
      while (!q.empty()) {
        int a = q.front().first;
        int b = q.front().second;
        q.pop();
        if (seen[a][b]) continue;
        seen[a][b] = 1;
        if (a < 1 || a > h) continue;
        if (b < 1 || b > w) continue;
        if (table[a][b] == '#') continue;
        if (table[a + 1][b] == '.' && !seen[a + 1][b]) {
          dist[a + 1][b] = dist[a][b] + 1;
          pair<int, int> next = make_pair(a + 1, b);
          q.push(next);
        }
        if (table[a - 1][b] == '.' && !seen[a - 1][b]) {
          dist[a - 1][b] = dist[a][b] + 1;
          pair<int, int> next = make_pair(a - 1, b);
          q.push(next);
        }
        if (table[a][b + 1] == '.' && !seen[a][b + 1]) {
          dist[a][b + 1] = dist[a][b] + 1;
          pair<int, int> next = make_pair(a, b + 1);
          q.push(next);
        }
        if (table[a][b - 1] == '.' && !seen[a][b - 1]) {
          dist[a][b - 1] = dist[a][b] + 1;
          pair<int, int> next = make_pair(a, b - 1);
          q.push(next);
        }
      }
      int tmp = 0;
      for (int i = 1; i < h + 1; i++)
        for (int j = 0; j < w; j++) tmp = max(tmp, dist[i][j]);
      ans = max(ans, tmp);
    }
  }
  cout << ans << endl;
}
