#include <bits/stdc++.h>
using namespace std;
int start_row, start_col, end_row, end_col;
int arr[] = {0, 0, -1, +1};
int brr[] = {-1, +1, 0, 0};
int coun = 0;
bool visited[25][25], vis2[25][25];
bool flag = false;
vector<pair<int, int>> v;
char ch[25][25];
int r, c;
int mn;
int ans[25][25];
queue<pair<int, int>> q;
int first, sec;
int mx = 0;
void bfs() {
  while (!q.empty()) {
    int u = q.front().first;
    int w = q.front().second;
    visited[u][w] = 1;
    q.pop();
    for (int i = 0; i < 4; i++) {
      int a = u + arr[i];
      int b = w + brr[i];
      if (a >= 1 && a <= r && b >= 1 && b <= c && visited[a][b] == 0 &&
          ch[a][b] == '.') {
        q.push({a, b});
        ans[a][b] = ans[u][w] + 1;
        if (ans[a][b] > mx) {
          mx = ans[a][b];
          first = a;
          sec = b;
        }
      }
    }
  }
}
int main() {
  cin >> r >> c;
  for (int i = 1; i <= r; i++) {
    for (int j = 1; j <= c; j++) {
      cin >> ch[i][j];
      if (ch[i][j] == '.') {
        v.push_back({i, j});
      }
    }
  }
  int len = v.size();
  int anss = 0;
  for (int i = 0; i < len; i++) {
    int a1 = v[i].first, a2 = v[i].second;
    if (visited[a1][a2] == 0) {
      q.push({a1, a2});
      ans[a1][a2] = 0;
      mx = 0;
      bfs();
      memset(visited, 0, sizeof(visited));
      q.push({first, sec});
      ans[first][sec] = 0;
      bfs();
      anss = max(anss, mx);
    }
  }
  cout << mx << "\n";
  return 0;
}
