#include <bits/stdc++.h>
using namespace std;
long long rr[] = {1, 0, -1, 0};
long long rc[] = {0, 1, 0, -1};
char grid[27][27];
long long dists[27][27];
class DMazeMaster {
 public:
  void solve(std::istream& in, std::ostream& out) {
    long long h, w;
    in >> h >> w;
    for (long long i = 0; i < h; i++)
      for (long long j = 0; j < w; j++) {
        in >> grid[i][j];
        dists[i][j] = -1;
      }
    pair<long long, long long> init = {-1, -1};
    for (long long i = 0; i < h; i++)
      for (long long j = 0; j < w; j++) {
        if (grid[i][j] == '.') {
          init = make_pair(i, j);
        }
      }
    if (init == make_pair(-1LL, -1LL)) {
      out << 0 << endl;
      return;
    }
    deque<pair<long long, long long> > left;
    left.push_back(init);
    dists[init.first][init.second] = 0;
    while (!left.empty()) {
      pair<long long, long long> cur = left.front();
      left.pop_front();
      for (long long i = 0; i < 4; i++) {
        long long x = cur.first + rr[i];
        long long y = cur.second + rc[i];
        if (x >= 0 && x < h && y >= 0 && y < w && grid[x][y] == '.' &&
            dists[x][y] == -1) {
          left.emplace_back(x, y);
          dists[x][y] = dists[cur.first][cur.second] + 1;
        }
      }
    }
    pair<long long, long long> max_p;
    long long maxx = -1;
    for (long long i = 0; i < h; i++)
      for (long long j = 0; j < w; j++) {
        if (dists[i][j] > maxx) {
          max_p = make_pair(i, j);
          maxx = dists[i][j];
        }
      }
    for (long long i = 0; i < h; i++)
      for (long long j = 0; j < w; j++) {
        dists[i][j] = -1;
      }
    init = max_p;
    deque<pair<long long, long long> > left2;
    left2.push_back(init);
    dists[init.first][init.second] = 0;
    while (!left2.empty()) {
      pair<long long, long long> cur = left2.front();
      left2.pop_front();
      for (long long i = 0; i < 4; i++) {
        long long x = cur.first + rr[i];
        long long y = cur.second + rc[i];
        if (x >= 0 && x < h && y >= 0 && y < w && grid[x][y] == '.' &&
            dists[x][y] == -1) {
          left2.emplace_back(x, y);
          dists[x][y] = dists[cur.first][cur.second] + 1;
        }
      }
    }
    long long maxxx = -1;
    for (long long i = 0; i < h; i++)
      for (long long j = 0; j < w; j++) {
        if (dists[i][j] > maxxx) {
          maxxx = dists[i][j];
        }
      }
    out << maxxx << endl;
  }
};
long long main() {
  DMazeMaster solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
}
