#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
ostream& operator<<(ostream& s, const complex<T>& d) {
  return s << "(" << d.real() << ", " << d.imag() << ")";
}
template <typename T1, typename T2>
ostream& operator<<(ostream& s, const pair<T1, T2>& d) {
  return s << "(" << d.first << ", " << d.second << ")";
}
template <typename T>
ostream& operator<<(ostream& s, const vector<T>& d) {
  int len = d.size();
  for (long long i = 0; i < len; i++) {
    s << d[i];
    if (i < len - 1) s << " ";
  }
  return s;
}
template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& d) {
  int len = d.size();
  for (long long i = 0; i < len; i++) {
    s << d[i] << endl;
  }
  return s;
}
template <typename T>
ostream& operator<<(ostream& s, const set<T>& v) {
  s << "{ ";
  for (auto itr = v.begin(); itr != v.end(); ++itr) {
    if (itr != v.begin()) {
      s << ", ";
    }
    s << (*itr);
  }
  s << " }";
  return s;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& s, const map<T1, T2>& m) {
  s << "{" << endl;
  for (auto itr = m.begin(); itr != m.end(); ++itr) {
    s << " " << (*itr).first << " : " << (*itr).second << endl;
  }
  s << "}" << endl;
  return s;
}
const long long mod = 1e9 + 7;
const long long inf = 1e17;
const int INF = 1e9;
const double PI = acos(-1);
const double EPS = 1e-10;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int h, w;
  cin >> h >> w;
  vector<string> g(h);
  for (long long i = 0; i < h; i++) {
    cin >> g[i];
  }
  auto bfs = [&](pair<int, int> s, pair<int, int> go) {
    if (s == go) return INF;
    vector<int> dx = {1, -1, 0, 0}, dy = {0, 0, 1, -1};
    queue<pair<int, int>> que;
    vector<vector<int>> dist(h, vector<int>(w, INF));
    que.push(s);
    dist[s.first][s.second] = 0;
    while (!que.empty()) {
      pair<int, int> now = que.front();
      que.pop();
      for (long long i = 0; i < 4; i++) {
        int nx = now.first + dx[i], ny = now.second + dy[i];
        if (0 <= nx && nx <= h - 1 && 0 <= ny && ny <= w - 1) {
          if (g[nx][ny] != '#' && dist[nx][ny] == INF) {
            dist[nx][ny] = dist[now.first][now.second] + 1;
            que.push(pair<int, int>(nx, ny));
          }
        }
      }
    }
    return dist[go.first][go.second];
  };
  int ans = 0;
  for (long long i = 0; i < h; i++)
    for (long long j = 0; j < w; j++)
      for (long long k = 0; k < h; k++)
        for (long long l = 0; l < w; l++) {
          int ret = bfs(pair<int, int>(i, j), pair<int, int>(k, l));
          if (ret == INF) continue;
          chmax(ans, ret);
        }
  cout << ans << endl;
}
