#include <bits/stdc++.h>
using namespace std;
long long int m, n;
long long int mat[21][21];
bool vis[21][21];
long long int res[21][21];
long long int x_mov[] = {0, 0, 1, -1};
long long int y_mov[] = {1, -1, 0, 0};
bool is_valid(long long int x, long long int y) {
  if (x < 0 || x >= m || y < 0 || y >= n || vis[x][y] || !mat[x][y])
    return false;
  return true;
}
long long int bfs(pair<long long int, long long int> src) {
  memset(vis, false, sizeof(vis));
  memset(res, 0, sizeof(res));
  vis[src.first][src.second] = true;
  res[src.first][src.second] = 0;
  queue<pair<long long int, long long int>> q;
  q.push(src);
  while (!q.empty()) {
    pair<long long int, long long int> pp = q.front();
    q.pop();
    for (long long int i = 0; i < 4; i++) {
      long long int new_x = pp.first + x_mov[i];
      long long int new_y = pp.second + y_mov[i];
      if (is_valid(new_x, new_y)) {
        res[new_x][new_y] = 1 + res[pp.first][pp.second];
        vis[new_x][new_y] = true;
        q.push({new_x, new_y});
      }
    }
  }
  long long int mx = INT_MIN;
  for (long long int i = 0; i < m; i++) {
    for (long long int j = 0; j < n; j++) {
      mx = max(mx, res[i][j]);
    }
  }
  return mx;
}
int32_t main() {
  cin >> m >> n;
  string str;
  for (long long int i = 0; i < m; i++) {
    cin >> str;
    for (long long int j = 0; str[j]; j++) {
      if (str[j] == '.')
        mat[i][j] = 1;
      else
        mat[i][j] = 0;
    }
  }
  pair<long long int, long long int> src;
  long long int ans = INT_MIN;
  for (long long int i = 0; i < m; i++) {
    for (long long int j = 0; j < n; j++) {
      ans = max(ans, bfs({i, j}));
    }
  }
  cout << ans << "\n";
  return 0;
}
