#include <bits/stdc++.h>
using namespace std;
int v[20][20] = {};
int cost[20][20] = {};
int maxw;
int maxh;
int ans = 0;
int coner(int h, int w) {
  int r = 0;
  if (h + 1 < maxh && v[h + 1][w]) r++;
  if (w + 1 < maxw && v[h][w + 1]) r++;
  if (w - 1 > -1 && v[h][w - 1]) r++;
  if (h - 1 > -1 && v[h - 1][w]) r++;
  return r;
}
int serch(int bcost, int h, int w) {
  cost[h][w] = bcost + 1;
  if (h + 1 < maxh) {
    if (v[h + 1][w] == true && cost[h + 1][w] + 1 < cost[h][w]) {
      cost[h][w] = cost[h + 1][w] + 1;
    } else if (v[h + 1][w] == true && cost[h + 1][w] > cost[h][w] + 1) {
      int newcost = serch(cost[h][w], h + 1, w);
      if (newcost + 1 < cost[h][w]) cost[h][w] = newcost + 1;
    }
  }
  if (h - 1 > -1) {
    if (v[h - 1][w] == true && cost[h - 1][w] + 1 < cost[h][w]) {
      cost[h][w] = cost[h - 1][w] + 1;
    } else if (v[h - 1][w] == true && cost[h - 1][w] > cost[h][w] + 1) {
      int newcost = serch(cost[h][w], h - 1, w);
      if (newcost + 1 < cost[h][w]) cost[h][w] = newcost + 1;
    }
  }
  if (w - 1 > -1) {
    if (v[h][w - 1] == true && cost[h][w - 1] + 1 < cost[h][w]) {
      cost[h][w] = cost[h][w - 1] + 1;
    } else if (v[h][w - 1] == true && cost[h][w - 1] > cost[h][w] + 1) {
      int newcost = serch(cost[h][w], h, w - 1);
      if (newcost + 1 < cost[h][w]) cost[h][w] = newcost + 1;
    }
  }
  if (w + 1 < maxw) {
    if (v[h][w + 1] == true && cost[h][w + 1] + 1 < cost[h][w]) {
      cost[h][w] = cost[h][w + 1] + 1;
    } else if (v[h][w + 1] == true && cost[h][w + 1] > cost[h][w] + 1) {
      int newcost = serch(cost[h][w], h, w + 1);
      if (newcost + 1 < cost[h][w]) cost[h][w] = newcost + 1;
    }
  }
  return cost[h][w];
}
int main() {
  std::cin >> maxh >> maxw;
  for (int i = 0; i < maxh; i++) {
    for (int k = 0; k < maxw; k++) {
      char temp;
      std::cin >> temp;
      v[i][k] = temp == '.' ? true : false;
      cost[i][k] = 9999999;
    }
  }
  bool flag = false;
  int min = 9999999;
  int start[2] = {};
  for (int i = 0; i < maxh; i++) {
    for (int k = 0; k < maxw; k++) {
      int now = coner(i, k);
      if (v[i][k] == true && now != 0 && min > now) {
        min = now;
        start[0] = i;
        start[1] = k;
      }
    }
  }
  serch(-1, start[0], start[1]);
  for (int i = 0; i < maxh; i++) {
    for (int k = 0; k < maxw; k++) {
      if (v[i][k] && cost[i][k] > ans) ans = cost[i][k];
    }
  }
  std::cout << ans << '\n';
  return 0;
}
