#include <bits/stdc++.h>
using namespace std;
bool in_bound(int x, int l, int r) { return l <= x && x < r; }
int main() {
  int n, m;
  cin >> n >> m;
  vector<string> s(n);
  for (int i = 0; i < n; ++i) {
    cin >> s[i];
  }
  vector<vector<int>> dist(n * m);
  for (int i = 0; i < n * m; ++i) {
    dist[i].resize(n * m);
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      for (int k = 0; k < n; ++k) {
        for (int l = 0; l < m; ++l) {
          dist[i * n + j][k * n + l] = 5000;
        }
      }
    }
  }
  int dx[] = {0, 0, 1, -1};
  int dy[] = {-1, 1, 0, 0};
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (s[i][j] != '.') continue;
      for (int k = 0; k < 4; ++k) {
        int x = i + dx[k];
        int y = j + dy[k];
        if (in_bound(x, 0, n) && in_bound(y, 0, m) && s[x][y] != '#') {
          dist[i * n + j][x * n + y] = 1;
        }
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      dist[i * n + j][i * n + j] = 0;
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (s[i][j] != '.') continue;
      for (int k = 0; k < n; ++k) {
        for (int l = 0; l < m; ++l) {
          if (s[k][l] != '.') continue;
          for (int p = 0; p < n; ++p) {
            for (int q = 0; q < m; ++q) {
              if (s[p][q] != '.') continue;
              int d = dist[k * n + l][i * n + j] + dist[i * n + j][p * n + q];
              dist[k * n + l][p * n + q] = min(dist[k * n + l][p * n + q], d);
            }
          }
        }
      }
    }
  }
  int max_dist = INT_MIN;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (s[i][j] != '.') continue;
      for (int k = 0; k < n; ++k) {
        for (int l = 0; l < m; ++l) {
          if (s[k][l] != '.') continue;
          max_dist = max(max_dist, dist[i * n + j][k * n + l]);
        }
      }
    }
  }
  cout << max_dist << '\n';
  return 0;
}
