#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 T>
ostream &operator<<(ostream &os, const unordered_set<T> &v) {
  os << "[";
  typename unordered_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 << "]";
}
template <typename F, typename S>
ostream &operator<<(ostream &os, const unordered_map<F, S> &v) {
  os << "[";
  typename unordered_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 << "]";
}
int n, m;
vector<vector<char>> a;
void read_input() {
  cin >> n >> m;
  a.resize(n, vector<char>(m));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
}
vector<int> ii = {0, 0, -1, 1};
vector<int> jj = {-1, 1, 0, 0};
int bfs(int i, int j, vector<vector<char>> a, int n, int m) {
  pair<int, int> curr;
  queue<pair<int, pair<int, int>>> q;
  int maxi = 0, dist;
  q.push({0, {i, j}});
  while (!q.empty()) {
    tie(dist, curr) = q.front();
    q.pop();
    maxi = max(maxi, dist);
    for (int k = 0; k < 4; k++) {
      int new_i = curr.first + ii[k];
      int new_j = curr.second + jj[k];
      if (new_i < 0 || new_i >= n) continue;
      if (new_j < 0 || new_j >= m) continue;
      if (a[new_i][new_j] == '.') {
        a[new_i][new_j] = '#';
        q.push({dist + 1, {new_i, new_j}});
      }
    }
  }
  return maxi;
}
void solve() {
  int solution = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a[i][j] == '.') {
        solution = max(solution, bfs(i, j, a, n, m));
      }
    }
  }
  cout << solution << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  read_input();
  solve();
  return 0;
}
