#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug& operator<<(const c&) {
    return *this;
  }
};
const int MOD = 1000000007;
const long long INFLL = 1e18;
const int INF = 1e9;
const int NMAX = 25;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
char matrix[NMAX][NMAX];
int matrixFill[NMAX][NMAX];
int sol = 0;
int n, m;
bool check(int x, int y) {
  if (x < 0 || x >= n) return false;
  if (y < 0 || y >= m) return false;
  if (matrix[x][y] == '#') return false;
  return true;
}
void BFS(int a, int b) {
  queue<pair<int, int>> coada;
  coada.push({a, b});
  while (!coada.empty()) {
    int x = coada.front().first;
    int y = coada.front().second;
    coada.pop();
    for (int i = 0; i < 4; ++i) {
      int next_x = x + dx[i];
      int next_y = y + dy[i];
      if (check(next_x, next_y) && matrixFill[next_x][next_y] == 0) {
        matrixFill[next_x][next_y] = matrixFill[x][y] + 1;
        sol = max(sol, matrixFill[next_x][next_y]);
        coada.push({next_x, next_y});
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    cin >> matrix[i];
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      memset(matrixFill, 0, sizeof(matrixFill));
      BFS(i, j);
    }
  }
  cout << sol;
  return 0;
}
