#include <bits/stdc++.h>
using namespace std;
long long const MOD = 1e9 + 7;
int const inf = 1e9;
long long const INF = 1e18;
inline void ios_() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}
template <typename T>
int size(const T& a) {
  return (int)a.size();
}
template <typename T>
T Div(T a, T b) {
  return (a + b - 1) / b;
}
template <typename T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
struct Graph {
  struct Edge {
    int from;
    int to;
    long long cost;
    Edge(int a, long long b) : to(a), cost(b) {}
    Edge(int a, int b, long long c) : from(a), to(b), cost(c) {}
  };
  int N;
  vector<vector<Edge>> edges;
  vector<long long> dist;
  long long diam;
  vector<int> deg;
  vector<int> cycle;
  Graph(int n) : N(n), edges(n), dist(n, INF), diam(INF), deg(n, 0) {}
  void setEdge(int a, int b, long long c) {
    edges[a].push_back(Edge(a, b, c));
    deg[b]++;
  }
  bool visited(int v) { return dist[v] < INF; }
  void resetDist() {
    for (int i = 0; i < N; i++) {
      dist[i] = INF;
    }
  }
  void dfs(int p, int v, long long d) {
    if (visited(v)) return;
    dist[v] = d;
    for (auto e : edges[v]) {
      if (e.to == p) continue;
      dfs(v, e.to, d + e.cost);
    }
  }
  void bfs(int v) {
    queue<Edge> que;
    for (auto i : edges[v]) que.push(i);
    dist[v] = 0;
    while (!que.empty()) {
      int u = que.front().to;
      long long d = que.front().cost;
      que.pop();
      for (auto e : edges[u]) {
        if (!visited(e.to)) {
          que.push(Edge(e.to, d + e.cost));
          dist[e.to] = d + e.cost;
        }
      }
    }
  }
  long long diameter() {
    if (diam != INF) return diam;
    dfs(-1, 0, 0);
    int v = max_element((dist).begin(), (dist).end()) - dist.begin();
    resetDist();
    dfs(-1, v, 0);
    return diam = *max_element((dist).begin(), (dist).end());
  }
  void dijkstra(int start) {
    dist[start] = 0;
    auto fn = [](Edge a, Edge b) { return a.cost > b.cost; };
    priority_queue<Edge, vector<Edge>, decltype(fn)> que(fn);
    for (auto e : edges[start]) que.push(e);
    while (!que.empty()) {
      auto v = que.top().to;
      auto d = que.top().cost;
      que.pop();
      if (visited(v))
        continue;
      else
        dist[v] = d;
      for (auto e : edges[v]) {
        if (dist[e.to] == INF) {
          que.push(Edge(e.to, e.cost + d));
        }
      }
    }
  }
  bool BellmanFord(int start) {
    dist[start] = 0;
    for (int(i) = 0; (i) < (N); (i)++) {
      for (int(j) = 0; (j) < (N); (j)++) {
        for (auto k : edges[j]) {
          if (visited(j) && dist[j] + k.cost < dist[k.to]) {
            if (i == N - 1) return true;
            dist[k.to] = dist[j] + k.cost;
          }
        }
      }
    }
    return false;
  }
  vector<int> topologicalSort() {
    queue<int> que;
    for (int(i) = 0; (i) < (N); (i)++) {
      if (deg[i] == 0) que.push(i);
    }
    vector<int> result;
    while (!que.empty()) {
      auto v = que.front();
      que.pop();
      result.push_back(v);
      for (auto e : edges[v]) {
        deg[e.to]--;
        if (deg[e.to] == 0) que.push(e.to);
      }
    }
    return result;
  }
  void findCycle(int p, int v) {
    static vector<bool> seen(N, false), finished(N, false);
    static int pos = -1;
    seen[v] = true;
    cycle.push_back(v);
    for (auto e : edges[v]) {
      if (e.to == p || finished[e.to]) continue;
      if (seen[e.to] && !finished[e.to]) {
        pos = e.to;
        return;
      }
      findCycle(v, e.to);
      if (pos != -1) return;
    }
    cycle.pop_back();
    finished[v] = true;
  }
};
signed main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> grid(h, vector<char>(w));
  for (int(i) = 0; (i) < (h); (i)++) {
    for (int(j) = 0; (j) < (w); (j)++) {
      cin >> grid[i][j];
    }
  }
  Graph G(h * w);
  vector<int> dx = {1, 0, -1, 0, 1, 1, -1, -1},
              dy = {0, 1, 0, -1, 1, -1, 1, -1};
  for (int(i) = 0; (i) < (h); (i)++) {
    for (int(j) = 0; (j) < (w); (j)++) {
      if (grid[i][j] == '#') continue;
      for (int(k) = 0; (k) < (4); (k)++) {
        int xi = i + dx[k], yi = j + dy[k];
        if (xi < 0 || xi >= h || yi < 0 || yi >= w) {
          continue;
        }
        if (grid[xi][yi] == '.') {
          G.setEdge(i * w + j, xi * w + yi, 1);
        }
      }
    }
  }
  for (int(i) = 0; (i) < (h * w); (i)++) {
    if (!G.edges[i].empty()) {
      G.bfs(i);
      break;
    }
  }
  int v = 0;
  long long d = -INF;
  for (int(i) = 0; (i) < (h * w); (i)++) {
    if (G.dist[i] < INF && chmax(d, G.dist[i])) {
      v = i;
    }
  }
  G.resetDist();
  G.bfs(v);
  long long ans = 0;
  for (int(i) = 0; (i) < (h * w); (i)++) {
    if (G.dist[i] < INF) {
      chmax(ans, G.dist[i]);
    }
  }
  cout << ans << endl;
  return 0;
}
