#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const unsigned long long int p = 5;
const unsigned long long int INF = 1000000000;
const unsigned long long int MAX_N = 2e5 + 2;
int v[21][21] = {0}, vis[21][21] = {0}, dist[21][21] = {0},
    dirsX[4] = {1, -1, 0, 0}, dirsY[4] = {0, 0, 1, -1}, r, c;
queue<pair<int, int>> q;
int solve(int sx, int sy) {
  pair<int, int> pr;
  while (!q.empty()) q.pop();
  for (int i = 0; i < r; ++i) {
    for (int j = 0; j < c; ++j) dist[i][j] = vis[i][j] = 0;
  }
  q.push({sx, sy}), dist[sx][sy] = 0, vis[sx][sy] = 1;
  while (!q.empty()) {
    pr = q.front();
    q.pop();
    for (int i = 0; i < 4; ++i) {
      int x = dirsX[i] + pr.first, y = dirsY[i] + pr.second;
      if (x >= r || y >= c || x < 0 || y < 0 || (vis[x][y] == 1) ||
          (v[x][y] == 0))
        continue;
      dist[x][y] = dist[pr.first][pr.second] + 1;
      vis[x][y] = 1;
      q.push({x, y});
    }
  }
  int temp = 0;
  for (int i = 0; i < r; ++i) {
    for (int j = 0; j < c; ++j) {
      temp = max(temp, dist[i][j]);
    }
  }
  return temp;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  cin >> r >> c;
  string s;
  for (int i = 0; i < r; ++i) {
    cin >> s;
    for (int j = 0; j < c; ++j) v[i][j] = (s[j] == '.');
  }
  int ans = 1;
  for (int i = 0; i < r; ++i) {
    for (int j = 0; j < c; ++j) {
      ans = max(ans, solve(i, j));
    }
  }
  cout << ans;
}
