#include <bits/stdc++.h>
using namespace std;
long long int res = 0;
void bfs(pair<long long int, long long int> a, vector<string> &v) {
  queue<pair<long long int, long long int> > q;
  long long int vis[25][25], d[25][25], n = v.size(), m = v[0].size();
  for (long long int i = 0; i < 25; i++)
    for (long long int j = 0; j < 25; j++) vis[i][j] = d[i][j] = 0;
  q.push(a);
  while (!q.empty()) {
    long long int i = q.front().first, j = q.front().second;
    q.pop();
    res = max(res, d[i][j]);
    vis[i][j] = 1;
    if (i > 0 && v[i - 1][j] == '.' && vis[i - 1][j] == 0) {
      q.push({i - 1, j});
      d[i - 1][j] = d[i][j] + 1;
    }
    if (i < n - 1 && v[i + 1][j] == '.' && vis[i + 1][j] == 0) {
      q.push({i + 1, j});
      d[i + 1][j] = d[i][j] + 1;
    }
    if (j > 0 && v[i][j - 1] == '.' && vis[i][j - 1] == 0) {
      q.push({i, j - 1});
      d[i][j - 1] = d[i][j] + 1;
    }
    if (j < m - 1 && v[i][j + 1] == '.' && vis[i][j + 1] == 0) {
      q.push({i, j + 1});
      d[i][j + 1] = d[i][j] + 1;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int h, w;
  cin >> h >> w;
  vector<string> v(h);
  for (long long int i = 0; i < h; i++) cin >> v[i];
  for (long long int x = 0; x < h; x++)
    for (long long int y = 0; y < w; y++)
      if (v[x][y] == '.') bfs({x, y}, v);
  cout << res;
}
