#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long INF = mod * mod;
const long double eps = 1e-12;
const long double pi = acos(-1.0);
long long qp(long long a, long long b, int mo) {
  int ans = 1;
  do {
    if (b & 1) ans = 1ll * ans * a % mo;
    a = 1ll * a * a % mo;
  } while (b >>= 1);
  return ans;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
template <typename T>
istream &operator>>(istream &is, vector<T> &vector<long long>) {
  for (auto &v : vector<long long>) is >> v;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vector<long long>) {
  os << "[";
  for (auto v : vector<long long>) os << v << ",";
  os << "]";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const deque<T> &vector<long long>) {
  os << "deq[";
  for (auto v : vector<long long>) os << v << ",";
  os << "]";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &vector<long long>) {
  os << "{";
  for (auto v : vector<long long>) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_set<T> &vector<long long>) {
  os << "{";
  for (auto v : vector<long long>) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const multiset<T> &vector<long long>) {
  os << "{";
  for (auto v : vector<long long>) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os,
                    const unordered_multiset<T> &vector<long long>) {
  os << "{";
  for (auto v : vector<long long>) os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &pa) {
  os << "(" << pa.first << "," << pa.second << ")";
  return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, const map<TK, TV> &mp) {
  os << "{";
  for (auto v : mp) os << v.first << "=>" << v.second << ",";
  os << "}";
  return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp) {
  os << "{";
  for (auto v : mp) os << v.first << "=>" << v.second << ",";
  os << "}";
  return os;
}
template <typename T>
void ndarray(vector<T> &vector<long long>, int len) {
  vector<long long>.resize(len);
}
template <typename T, typename... Args>
void ndarray(vector<T> &vector<long long>, int len, Args... args) {
  vector<long long>.resize(len);
  for (auto &v : vector<long long>) ndarray(v, args...);
}
template <typename T>
bool chmax(T &m, const T q) {
  if (m < q) {
    m = q;
    return true;
  } else
    return false;
}
template <typename T>
bool chmin(T &m, const T q) {
  if (q < m) {
    m = q;
    return true;
  } else
    return false;
}
template <typename T1, typename T2>
pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) {
  return make_pair(l.first + r.first, l.second + r.second);
}
template <typename T1, typename T2>
pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) {
  return make_pair(l.first - r.first, l.second - r.second);
}
void solve() {
  int H, W;
  cin >> H >> W;
  char field[H][W];
  int count[H][W];
  pair<int, int> start;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      char c;
      cin >> c;
      field[i][j] = c;
      if (c == '.') start = pair<int, int>(i, j);
      count[i][j] = -1;
    }
  }
  queue<pair<int, int> > q;
  q.push(start);
  count[start.first][start.second] = 0;
  int max = 0;
  pair<int, int> max_pair = start;
  while (!q.empty()) {
    pair<int, int> now = q.front();
    q.pop();
    for (int d = 0; d < 4; d++) {
      int x = dx[d] + now.first;
      int y = dy[d] + now.second;
      if (x < 0 || x >= H || y < 0 || y >= W) continue;
      if (field[x][y] == '.' && count[x][y] == -1) {
        count[x][y] = count[now.first][now.second] + 1;
        q.push(pair<int, int>(x, y));
        if (chmax(max, count[x][y])) max_pair = pair<int, int>(x, y);
      }
    }
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      count[i][j] = -1;
    }
  }
  start = max_pair;
  q.push(start);
  count[start.first][start.second] = 0;
  while (!q.empty()) {
    pair<int, int> now = q.front();
    q.pop();
    for (int d = 0; d < 4; d++) {
      int x = dx[d] + now.first;
      int y = dy[d] + now.second;
      if (x < 0 || x >= H || y < 0 || y >= W) continue;
      if (field[x][y] == '.' && count[x][y] == -1) {
        count[x][y] = count[now.first][now.second] + 1;
        q.push(pair<int, int>(x, y));
        if (chmax(max, count[x][y])) max_pair = pair<int, int>(x, y);
      }
    }
  }
  cout << max << endl;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  std::cout << fixed << setprecision(10);
  solve();
  return 0;
}
