#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 << "]";
}
bool BFS(vector<int64_t> adj[], int64_t src, int64_t dest, int64_t v,
         int64_t pred[], int64_t dist[]) {
  list<int64_t> queue;
  bool visited[v];
  for (int64_t i = 0; i < v; i++) {
    visited[i] = false;
    dist[i] = 1e18;
    pred[i] = -1;
  }
  visited[src] = true;
  dist[src] = 0;
  queue.push_back(src);
  while (!queue.empty()) {
    int64_t u = queue.front();
    queue.pop_front();
    for (int64_t i = 0; i < adj[u].size(); i++) {
      if (visited[adj[u][i]] == false) {
        visited[adj[u][i]] = true;
        dist[adj[u][i]] = dist[u] + 1;
        pred[adj[u][i]] = u;
        queue.push_back(adj[u][i]);
        if (adj[u][i] == dest) return true;
      }
    }
  }
  return false;
}
int64_t printShortestDistance(vector<int64_t> adj[], int64_t s, int64_t dest,
                              int64_t v) {
  int64_t pred[v], dist[v];
  if (BFS(adj, s, dest, v, pred, dist) == false) {
    return -1;
  }
  return dist[dest];
}
signed main() {
  vector<int64_t> adj[1007];
  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++) {
    for (int64_t j = 0; j <= n * m - 1; j++) {
      if (i != j) {
        int64_t x = printShortestDistance(adj, i, j, n * m - 1);
        ans = max(ans, x);
      }
    }
  }
  cout << ans << endl;
}
