#include <bits/stdc++.h>
using namespace std;
long long int r, c;
char ch[100][100];
long long int bfs(long long int x1, long long int y1) {
  long long int d[r][c];
  memset(d, -1, sizeof(d));
  queue<pair<long long int, long long int> > q;
  q.push(make_pair(x1, y1));
  d[x1][y1] = 0;
  while (!q.empty()) {
    long long int x = q.front().first;
    long long int y = q.front().second;
    q.pop();
    if (x + 1 < r and ch[x + 1][y] == '.' and d[x + 1][y] == -1)
      q.push(make_pair(x + 1, y)), d[x + 1][y] = d[x][y] + 1;
    if (x - 1 > -1 and ch[x - 1][y] == '.' and d[x - 1][y] == -1)
      q.push(make_pair(x - 1, y)), d[x - 1][y] = d[x][y] + 1;
    if (y + 1 < c and ch[x][y + 1] == '.' and d[x][y + 1] == -1)
      q.push(make_pair(x, y + 1)), d[x][y + 1] = d[x][y] + 1;
    if (y - 1 > -1 and ch[c][y - 1] == '.' and d[x][y - 1] == -1)
      q.push(make_pair(x, y - 1)), d[x][y - 1] = d[x][y] + 1;
  }
  long long int ans = 0;
  for (long long int i = 0; i < r; i++)
    for (long long int j = 0; j < c; j++) ans = max(ans, d[i][j]);
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> r >> c;
  vector<pair<long long int, long long int> > v;
  long long int res = 0;
  for (long long int i = 0; i < r; i++)
    for (long long int j = 0; j < c; j++) cin >> ch[i][j];
  for (long long int i = 0; i < r; i++) {
    for (long long int j = 0; j < c; j++) {
      if (ch[i][j] == '.') res = max(res, bfs(i, j));
    }
  }
  cout << res << endl;
}
