#include <bits/stdc++.h>
using namespace std;
long long dis[40][40];
char l[40][40];
queue<pair<int, int> > q;
long long ma;
pair<int, int> maj;
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cin >> l[i][j];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      q.push({i, j});
      for (int b = 0; b < n; i++) {
        for (int k = 0; k < m; j++) dis[b][k] = -1;
      }
      dis[i][j] = 0;
      while (q.size()) {
        int i = q.front().first, j = q.front().second;
        q.pop();
        if (dis[i][j] > ma) ma = dis[i][j];
        if (i + 1 < n and l[i + 1][j] == '.' and dis[i + 1][j] == -1) {
          dis[i + 1][j] = dis[i][j] + 1;
          q.push({i + 1, j});
        }
        if (j + 1 < m and l[i][j + 1] == '.' and dis[i][j + 1] == -1) {
          dis[i][j + 1] = dis[i][j] + 1;
          q.push({i, j + 1});
        }
        if (i - 1 > -1 and l[i - 1][j] == '.' and dis[i - 1][j] == -1) {
          dis[i - 1][j] = dis[i][j] + 1;
          q.push({i - 1, j});
        }
        if (j - 1 > -1 and l[i][j - 1] == '.' and dis[i][j - 1] == -1) {
          dis[i][j - 1] = dis[i][j] + 1;
          q.push({i, j - 1});
        }
      }
    }
  }
  cout << ma;
}
