#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T>
using V = vector<T>;
template <class T, class U>
using P = pair<T, U>;
template <class T>
using PQ = priority_queue<T>;
template <class T>
using PQR = priority_queue<T, vector<T>, greater<T>>;
const int MAX = 1000000;
const int MOD = 1000000007;
V<V<int>> reached;
V<V<int>> ori;
int h, w;
int px, py;
int searchS() {
  for (int i = (0); i < (h); i++) {
    for (int j = (0); j < (w); j++) {
      if (reached[i][j] == 1000) {
        px = i;
        py = j;
        return 1;
      }
    }
  }
  return 0;
}
int search() {
  int ma = 0;
  V<V<int>> lmap = ori;
  queue<int> x, y;
  x.push(px);
  y.push(py);
  lmap[px][py] = 0;
  while (!x.empty()) {
    int nx = x.front();
    x.pop();
    int ny = y.front();
    y.pop();
    reached[nx][ny] = 1;
    int nex, ney;
    nex = nx - 1;
    ney = ny;
    if (nex >= 0 && lmap[nex][ney] != -1 && lmap[nex][ney] > lmap[nx][ny]) {
      lmap[nex][ney] = lmap[nx][ny] + 1;
      x.push(nex);
      y.push(ney);
      if (lmap[nx][ny] + 1 > ma) {
        ma = lmap[nx][ny] + 1;
        px = nex;
        py = ney;
      }
    }
    nex = nx;
    ney = ny - 1;
    if (ney >= 0 && lmap[nex][ney] != -1 && lmap[nex][ney] > lmap[nx][ny]) {
      lmap[nex][ney] = lmap[nx][ny] + 1;
      x.push(nex);
      y.push(ney);
      if (lmap[nx][ny] + 1 > ma) {
        ma = lmap[nx][ny] + 1;
        px = nex;
        py = ney;
      }
    }
    nex = nx + 1;
    ney = ny;
    if (nex < h && lmap[nex][ney] != -1 && lmap[nex][ney] > lmap[nx][ny]) {
      lmap[nex][ney] = lmap[nx][ny] + 1;
      x.push(nex);
      y.push(ney);
      if (lmap[nx][ny] + 1 > ma) {
        ma = lmap[nx][ny] + 1;
        px = nex;
        py = ney;
      }
    }
    nex = nx;
    ney = ny + 1;
    if (ney < w && lmap[nex][ney] != -1 && lmap[nex][ney] > lmap[nx][ny]) {
      lmap[nex][ney] = lmap[nx][ny] + 1;
      x.push(nex);
      y.push(ney);
      if (lmap[nx][ny] + 1 > ma) {
        ma = lmap[nx][ny] + 1;
        px = nex;
        py = ney;
      }
    }
  }
  return ma;
}
int main() {
  string s;
  cin >> h >> w;
  V<V<int>> c;
  V<string> map;
  for (int i = (0); i < (h); i++) {
    V<int> v(w, 1000);
    ori.push_back(v);
    reached.push_back(v);
    cin >> s;
    map.push_back(s);
  }
  for (int i = (0); i < (h); i++) {
    for (int j = (0); j < (w); j++) {
      if (map[i][j] == '#') {
        reached[i][j] = -1;
        ori[i][j] = -1;
      }
    }
  }
  int ma = 0;
  while (searchS() != 0) {
    int t = search();
    if (ma < t) ma = t;
    t = search();
    if (ma < t) ma = t;
  }
  cout << ma << endl;
}
