#include <bits/stdc++.h>
using namespace std;
long long GCD(long long a, long long b) {
  if (b == 0) return a;
  return GCD(b, a % b);
}
char S[21][21];
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int solve(int H, int W, int si, int sj, int gi, int gj) {
  int dist[H][W];
  for (int i = (int)(0); i < (int)(H); ++i) {
    for (int j = (int)(0); j < (int)(W); ++j) dist[i][j] = -1;
  }
  dist[si][sj] = 0;
  queue<pair<int, int> > q;
  q.push(make_pair(si, sj));
  while (!q.empty()) {
    pair<int, int> current_pos = q.front();
    int x = current_pos.first;
    int y = current_pos.second;
    q.pop();
    for (int direction = 0; direction < 4; ++direction) {
      int next_x = x + dx[direction];
      int next_y = y + dy[direction];
      if (next_x < 0 || next_x >= H || next_y < 0 || next_y >= W) continue;
      if (S[next_x][next_y] == '#') continue;
      if (dist[next_x][next_y] == -1) {
        q.push(make_pair(next_x, next_y));
        dist[next_x][next_y] = dist[x][y] + 1;
      }
    }
  }
  return dist[gi][gj];
}
int main() {
  int H, W;
  cin >> H >> W;
  for (int i = (int)(0); i < (int)(H); ++i) {
    for (int j = (int)(0); j < (int)(W); ++j) cin >> S[i][j];
  }
  int res = 0;
  for (int i = (int)(0); i < (int)(H); ++i) {
    for (int j = (int)(0); j < (int)(W); ++j) {
      for (int k = (int)(0); k < (int)(H); ++k) {
        for (int l = (int)(0); l < (int)(W); ++l) {
          res = max(res, solve(H, W, i, j, k, l));
        }
      }
    }
  }
  cout << res << endl;
}
