#include <bits/stdc++.h>
using namespace std;
long long INFl = 1e+18 + 1;
int INF = 1e+9 + 1;
int N;
vector<pair<int, int> > adj[500];
int d[10000], color[10000], p[10000];
int dp[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
void dijkstra(int st) {
  priority_queue<pair<int, int> > PQ;
  for (int i = 0; i < N; i++) {
    d[i] = INF;
    color[i] = 0;
  }
  d[st] = 0;
  color[st] = 1;
  PQ.push(make_pair(0, st));
  while (!PQ.empty()) {
    pair<int, int> f = PQ.top();
    PQ.pop();
    int u = f.second;
    color[u] = 2;
    if (d[u] < -f.first) continue;
    for (int j = 0; j < adj[u].size(); j++) {
      int v = adj[u][j].first;
      if (color[v] == 2) continue;
      if (d[v] > d[u] + adj[u][j].second) {
        d[v] = d[u] + adj[u][j].second;
        PQ.push(make_pair(-d[v], v));
        color[v] = 1;
      }
    }
  }
}
int main() {
  int H, W;
  char S[25][25];
  int sti, stj;
  cin >> H >> W;
  int dismin[25][25];
  fill(dismin[0], dismin[25], INF);
  for (int i = 1; i <= H; i++) {
    cin >> S[i] + 1;
  }
  for (int i = 0; i < H + 2; i++) S[i][0] = '#', S[i][W + 1] = '#';
  for (int j = 0; j < W + 2; j++) S[0][j] = '#', S[H + 1][j] = '#';
  for (int i = 0; i < H + 2; i++)
    for (int j = 0; j < W + 2; j++)
      if (S[i][j] == '.') sti = i, stj = j;
  pair<int, int> st = {sti, stj};
  dismin[st.first][st.second] = 0;
  vector<pair<int, int> > zahyorecord;
  zahyorecord.push_back(st);
  for (int count = 1;; count++) {
    if (zahyorecord.empty()) break;
    vector<pair<int, int> > zahyobefore = zahyorecord;
    zahyorecord.clear();
    for (int i = 0; i < zahyobefore.size(); i++) {
      for (int j = 0; j < 4; j++) {
        pair<int, int> zahyoto = zahyobefore[i];
        int y = zahyoto.first + dp[j][1];
        int x = zahyoto.second + dp[j][0];
        if (S[y][x] == '.' && count < dismin[y][x]) {
          zahyorecord.push_back(make_pair(y, x));
          dismin[y][x] = count;
        }
      }
    }
  }
  int dmax = 0;
  int mi, mj;
  for (int i = 0; i < H + 2; i++)
    for (int j = 0; j < W + 2; j++)
      if (dismin[i][j] != INF && dismin[i][j] > dmax)
        mi = i, mj = j, dmax = dismin[i][j];
  fill(dismin[0], dismin[25], INF);
  st = {mi, mj};
  dismin[mi][mj] = 0;
  zahyorecord.clear();
  zahyorecord.push_back(st);
  for (int count = 1;; count++) {
    if (zahyorecord.empty()) break;
    vector<pair<int, int> > zahyobefore = zahyorecord;
    zahyorecord.clear();
    for (int i = 0; i < zahyobefore.size(); i++) {
      for (int j = 0; j < 4; j++) {
        pair<int, int> zahyoto = zahyobefore[i];
        int y = zahyoto.first + dp[j][1];
        int x = zahyoto.second + dp[j][0];
        if (S[y][x] == '.' && count < dismin[y][x]) {
          zahyorecord.push_back(make_pair(y, x));
          dismin[y][x] = count;
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < H + 2; i++)
    for (int j = 0; j < W + 2; j++)
      if (dismin[i][j] != INF) ans = max(ans, dismin[i][j]);
  cout << ans << endl;
  return 0;
}
