#include <bits/stdc++.h>
using namespace std;
const int dx[] = {+1, -1, +0, +0};
const int dy[] = {+0, +0, +1, -1};
const int dx8[] = {+0, +0, +1, -1, -1, +1, -1, +1};
const int dy8[] = {-1, +1, +0, +0, +1, +1, -1, -1};
const int kx[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int ky[] = {-1, 1, -2, 2, -2, 2, -1, 1};
int Set(int N, int pos) { return N = N | (1 << pos); }
int reset(int N, int pos) { return N = N & ~(1 << pos); }
bool check(int N, int pos) { return (bool)(N & (1 << pos)); }
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
const int maxe = 30;
vector<string> grid;
vector<vector<bool>> visited;
vector<vector<int>> level;
int h, w;
void bfs(int x_sos, int y_sos) {
  queue<pair<int, int>> Q;
  Q.push({x_sos, y_sos});
  visited[x_sos][y_sos] = true;
  level[x_sos][y_sos] = 0;
  while (!Q.empty()) {
    pair<int, int> p = Q.front();
    Q.pop();
    int xx = p.first;
    int yy = p.second;
    for (int i = 0; i < 4; i++) {
      int ux = xx + dx[i];
      int uy = yy + dy[i];
      if (ux >= 0 && ux < h && uy >= 0 && uy <= w && visited[ux][uy] == false &&
          grid[ux][uy] != '#') {
        visited[ux][uy] = true;
        Q.push({ux, uy});
        level[ux][uy] = level[xx][yy] + 1;
      }
    }
  }
}
int main(void) {
  cin >> h >> w;
  visited.assign(maxe, vector<bool>(maxe, false));
  level.assign(maxe, vector<int>(maxe, 0));
  for (int i = 0; i < h; i++) {
    string s;
    cin >> s;
    grid.push_back(s);
  }
  bool bol = false;
  for (int i = 0; i < grid.size(); i++) {
    for (int j = 0; j < grid[i].size(); j++) {
      if (grid[i][j] != '#') {
        bfs(i, j);
        bol = true;
        break;
      }
    }
    if (bol != false) break;
  }
  int maxe_x = 0, maxe_y = 0;
  int lev = 0;
  for (int i = 0; i < grid.size(); i++) {
    for (int j = 0; j < grid[i].size(); j++) {
      if (level[i][j] >= lev) {
        maxe_x = i;
        maxe_y = j;
        lev = level[i][j];
      }
    }
  }
  visited.assign(maxe, vector<bool>(maxe, false));
  level.assign(maxe, vector<int>(maxe, 0));
  bfs(maxe_x, maxe_y);
  lev = 0;
  for (int i = 0; i < grid.size(); i++) {
    for (int j = 0; j < grid[i].size(); j++) {
      if (level[i][j] >= lev) {
        lev = level[i][j];
      }
    }
  }
  cout << lev << endl;
  return 0;
}
