/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-01-12 20:04:03
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#ifdef LOCAL
#define debug(_) cerr << #_ << ": " << (_) << '\n'
#else
#define debug(_) 1728
#endif

template <class T>
class TreeDiameter {
 public:
  TreeDiameter(int node_size) : node_size_(node_size) { Initialize(); }

  void AddEdge(int from, int to, T cost) {
    graph_[from].push_back({cost, to});
    //graph_[to].push_back({cost, from});
  }

  T GetDiameter() { return BFS(BFS(0).second).first; }

 private:
  struct edge {
    T cost;
    int to;
  };
  int node_size_;
  std::vector<std::vector<edge>> graph_;

  void Initialize() { graph_.resize(node_size_); }

  std::pair<T, int> BFS(int source) {
    std::pair<T, int> result = {static_cast<T>(0), 0};
    std::queue<int> q;
    bool visited[node_size_] = {};
    vector<T> dist(node_size_, 0);
    visited[source] = true;
    q.push(source);
    while (!q.empty()) {
      int top = q.front();
      q.pop();
      for (const auto& next : graph_[top]) {
        if (visited[next.to]) continue;
        visited[next.to] = true;
        dist[next.to] += dist[top] + next.cost;
        q.push(next.to);
        result = max(result, {dist[next.to], next.to});
      }
    }
    return result;
  }
};

constexpr int dx[4] = {1, 0, -1, 0};
constexpr int dy[4] = {0, 1, 0, -1};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int h, w; cin >> h >> w;
  TreeDiameter<int> td(h * w);

  char s[22][22];
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) cin >> s[i][j];
  }

  auto ok = [&](int x, int y) {
    return x >= 0 && x < h && y >= 0 && y < w && s[x][y] != '#';
  };

  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      for (int k = 0; k < 4; ++k) {
        int nx = i + dx[k], ny = j + dy[k];
        if (ok(nx, ny)) {
          td.AddEdge(i * w + j, nx * w + ny, 1);
        }
      }
    }
  }

  cout << td.GetDiameter() << endl;

  return 0;
}