#include <bits/stdc++.h>
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/stack:200000000")
using namespace std;
void io() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
}
long long h, w;
char s[25][25];
int a[25][25];
bool vis[25][25];
int d[4][2] = {1, 0, 0, 1, -1, 0, 0, -1};
void bfs(pair<int, int> p) {
  memset(vis, false, sizeof(vis));
  queue<pair<int, int> > q;
  q.push(p);
  vis[p.first][p.second] = true;
  while (!q.empty()) {
    pair<int, int> tp = q.front();
    int dep = a[tp.first][tp.second] + 1;
    q.pop();
    for (int i = 0; i <= 3; ++i) {
      if (tp.first + d[i][0] < 1 || tp.first + d[i][0] > h ||
          tp.second + d[i][1] < 1 || tp.second + d[i][1] > w)
        continue;
      if (vis[tp.first + d[i][0]][tp.second + d[i][1]]) continue;
      if (a[tp.first + d[i][0]][tp.second + d[i][1]] == -1) continue;
      a[tp.first + d[i][0]][tp.second + d[i][1]] = dep;
      vis[tp.first + d[i][0]][tp.second + d[i][1]] = true;
      q.push(make_pair(tp.first + d[i][0], tp.second + d[i][1]));
    }
  }
}
int main() {
  io();
  cin >> h >> w;
  for (int i = 1; i <= h; ++i) cin >> (s[i] + 1);
  for (int i = 1; i <= h; ++i) {
    for (int j = 1; j <= w; ++j) {
      if (s[i][j] == '#') {
        a[i][j] = -1;
      }
    }
  }
  for (int i = 1; i <= h; ++i) {
    for (int j = 1; j <= w; ++j) {
      if (a[i][j] == -1 || vis[i][j]) continue;
      bfs(make_pair(i, j));
    }
  }
  int maxd = 0;
  pair<int, int> st;
  for (int i = 1; i <= h; ++i) {
    for (int j = 1; j <= w; ++j) {
      if (a[i][j] == -1) continue;
      if (a[i][j] > maxd) {
        maxd = a[i][j];
        st = make_pair(i, j);
      }
      a[i][j] = 0;
    }
  }
  bfs(st);
  maxd = 0;
  for (int i = 1; i <= h; ++i) {
    for (int j = 1; j <= w; ++j) {
      maxd = max(maxd, a[i][j]);
    }
  }
  cout << maxd;
}
