#include <bits/stdc++.h>
using namespace std;
class Edge {
 public:
  int cost;
  int from;
  int to;
  Edge(int n, int c) {
    to = n;
    cost = c;
  }
  Edge(int f, int t, int c) {
    from = f;
    to = t;
    cost = c;
  }
};
vector<Edge> g[400];
string s[20];
pair<int, int> bfs(int now) {
  bool used[400];
  int d[400];
  fill(used, used + 400, false);
  fill(d, d + 400, -1);
  deque<pair<int, int> > q;
  q.push_back(pair<int, int>(0, now));
  while (!q.empty()) {
    pair<int, int> p = q[0];
    q.pop_front();
    if (used[p.second]) continue;
    d[p.second] = p.first;
    used[p.second] = true;
    for (int i = 0; i < g[p.second].size(); i++) {
      Edge e = g[p.second][i];
      if (used[e.to]) continue;
      q.push_back(pair<int, int>(p.first + 1, e.to));
    }
  }
  pair<int, int> ret = pair<int, int>(-1, -1);
  for (int i = 0; i < 400; i++) {
    ret = max(ret, pair<int, int>(d[i], i));
  }
  return ret;
}
int main() {
  int h, w;
  int dx[4] = {0, 1, 0, -1};
  int dy[4] = {1, 0, -1, 0};
  cin >> h >> w;
  for (int i = 0; i < h; i++) cin >> s[i];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      for (int k = 0; k < 4; k++) {
        if (i + dx[k] >= 0 && i + dx[k] < h && j + dy[k] >= 0 &&
            j + dy[k] < w) {
          if (s[i + dx[k]][j + dy[k]] == '.')
            g[i * 20 + j].push_back(Edge((i + dx[k]) * 20 + (dy[k] + j), 1));
        }
      }
    }
  }
  cerr << "doe" << endl;
  pair<int, int> z = bfs(0);
  pair<int, int> ans = bfs(z.second);
  cout << ans.first << endl;
  return 0;
}
