#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (a > b) {
    swap(a, b);
  }
  while (b % a != 0) {
    b %= a;
    swap(a, b);
  }
  return a;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
int xoror(int a, int b) { return 0; }
int solve(vector<vector<int>> B, int i, int H, int W) {
  int h = i % W, w = (i + W - 1) / W, N = H * W, ans2 = 0;
  if (h == 0) h = W;
  h--;
  w--;
  B[h][w] == 0;
  vector<vector<pair<int, int>>> V(
      N, vector<pair<int, int>>(N, pair<int, int>(0, 0)));
  V[0][0].first = h;
  V[0][0].second = w;
  vector<int> VV(N, 0);
  VV[0] = 1;
  for (int j = 0; j <= N; j++) {
    int count = 0;
    vector<int> HA(VV[j], 0);
    vector<int> WA(VV[j], 0);
    for (int k = 0; k < VV[j]; k++) {
      HA[k] = V[0][k].first;
      WA[k] = V[0][k].second;
      int ha = HA[k], wa = WA[k];
      if (ha - 1 >= 0 && B[ha - 1][wa] == 1000) {
        B[ha - 1][wa] = j + 1;
        V[j][count].first = ha - 1;
        V[j][count].second = wa;
        count++;
      }
      if (ha + 1 >= H - 1 && B[ha + 1][wa] == 1000) {
        B[ha + 1][wa] = j + 1;
        V[j][count].first = ha + 1;
        V[j][count].second = wa;
        count++;
      }
      if (wa - 1 >= 0 && B[ha][wa - 1] == 1000) {
        B[ha][wa - 1] = j + 1;
        V[j][count].first = ha;
        V[j][count].second = wa - 1;
        count++;
      }
      if (wa + 1 >= W - 1 && B[ha][wa + 1] == 1000) {
        B[ha][wa + 1] = j + 1;
        V[j][count].first = ha;
        V[j][count].second = wa + 1;
        count++;
      }
    }
    VV[j + 1] = count;
  }
  for (int j = 1; j <= N; j++) {
    int hg = i % W, wg = (i + W - 1) / W;
    if (hg == 0) hg = W;
    hg--;
    wg--;
    if (B[hg][wg] < 1000) {
      ans2 = max(ans2, B[hg][wg]);
    }
  }
  return ans2;
}
int main() {
  int H, W, ans;
  cin >> H >> W;
  int N = H * W;
  vector<vector<char>> A(H, vector<char>(W));
  vector<vector<int>> B(H, vector<int>(W, 1000));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> A[i][j];
      if (A[i][j] == '#') {
        B[i][j] = 10000;
      }
    }
  }
  for (int i = 1; i <= N; i++) {
    int h = i % W, w = (i + W - 1) / W;
    if (h == 0) h = W;
    h--;
    w--;
    if (A[h][w] == '#') continue;
    int ans2 = solve(B, i, H, W);
    ans = max(ans, ans2);
  }
  cout << ans << endl;
}
