#include <bits/stdc++.h>
using namespace std;
template <typename F, typename S>
ostream &operator<<(ostream &os, const pair<F, S> &p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  typename vector<T>::const_iterator it;
  for (it = v.begin(); it != v.end(); it++) {
    if (it != v.begin()) os << ", ";
    os << *it;
  }
  return os << "}";
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &v) {
  os << "[";
  typename set<T>::const_iterator it;
  for (it = v.begin(); it != v.end(); it++) {
    if (it != v.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}
template <typename F, typename S>
ostream &operator<<(ostream &os, const map<F, S> &v) {
  os << "[";
  typename map<F, S>::const_iterator it;
  for (it = v.begin(); it != v.end(); it++) {
    if (it != v.begin()) os << ", ";
    os << it->first << " = " << it->second;
  }
  return os << "]";
}
signed main() {
  vector<int64_t> adj[107];
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int64_t n, m;
  cin >> n >> m;
  char a[n][m];
  for (int64_t i = 0; i < n; i++) {
    for (int64_t j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  int64_t dx[] = {0, -1, 1, 0};
  int64_t dy[] = {1, 0, 0, -1};
  for (int64_t i = 0; i < n; i++) {
    for (int64_t j = 0; j < m; j++) {
      if (a[i][j] == '.')
        for (int64_t k = 0; k < 4; k++) {
          int64_t X = i + dx[k];
          int64_t Y = j + dy[k];
          if (X < n && X >= 0 && Y < m && Y >= 0) {
            if (a[X][Y] == '.') adj[i * m + j].push_back(X * m + Y);
          }
        }
    }
  }
  int64_t ans = 0;
  for (int64_t i = 0; i < n * m - 1; i++) {
    vector<int64_t> dist(123, 1e18);
    dist[i] = 0;
    queue<int64_t> que;
    que.push(i);
    int64_t u;
    while (!que.empty()) {
      u = que.front();
      for (int64_t i = 0; i < adj[u].size(); i++) {
        if (dist[adj[u][i]] > dist[u] + 1) {
          dist[adj[u][i]] = dist[u] + 1;
          que.push(adj[u][i]);
        }
      }
      que.pop();
    }
    int64_t temp = 0;
    for (int64_t i = 0; i < n * m - 1; i++) {
      if (dist[i] != 1e18) {
        temp = max(temp, dist[i]);
      }
    }
    ans = max(ans, temp);
  }
  cout << ans << endl;
}
