#include <bits/stdc++.h>
using namespace std;
const long long inf = 0x3f3f3f3f;
template <typename S, typename T>
ostream& operator<<(ostream& out, pair<S, T> const& p) {
  out << '(' << p.first << ", " << p.second << ')';
  return out;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T> const& v) {
  long long l = v.size();
  for (long long i = 0; i < l - 1; i++) out << v[i] << ' ';
  if (l > 0) out << v[l - 1];
  return out;
}
int h, w;
string s[21];
int bfs(int i, int j) {
  map<pair<int, int>, int> dis;
  queue<pair<int, int>> q;
  dis[{i, j}] = 0;
  q.push({i, j});
  while (!q.empty()) {
    int i = q.front().first;
    int j = q.front().second;
    q.pop();
    if (i + 1 < h && s[i + 1][j] == '.' && dis[{i + 1, j}] == 0) {
      dis[{i + 1, j}] = dis[{i, j}] + 1;
      q.push({i + 1, j});
    }
    if (i - 1 > -1 && s[i - 1][j] == '.' && dis[{i - 1, j}] == 0) {
      dis[{i - 1, j}] = dis[{i, j}] + 1;
      q.push({i - 1, j});
    }
    if (j + 1 < w && s[i][j + 1] == '.' && dis[{i, j + 1}] == 0) {
      dis[{i, j + 1}] = dis[{i, j}] + 1;
      q.push({i, j + 1});
    }
    if (j - 1 < w && s[i][j - 1] == '.' && dis[{i, j - 1}] == 0) {
      dis[{i, j - 1}] = dis[{i, j}] + 1;
      q.push({i, j - 1});
    }
  }
  int mx = 0;
  for (auto x : dis) {
    mx = max(x.second, mx);
  }
  return mx;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> h >> w;
  for (int i = 0; i < h; ++i) {
    cin >> s[i];
  }
  int ans = 0;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (s[i][j] != '#') ans = max(ans, bfs(i, j));
    }
  }
  cout << ans << endl;
}
