#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int N = 1e5;
const int MOD = 1e9 + 7;
const double PI = acos(-1);
char a[21][21];
int h, w;
set<pair<int, int>> used;
int way;
void bfs(pair<int, int> cur, pair<int, int> to) {
  queue<pair<pair<int, int>, int>> q;
  q.push({cur, 0});
  used.insert(cur);
  while (!q.empty()) {
    auto f = q.front();
    q.pop();
    pair<int, int> p = f.first;
    if (f.first == to) way = min(way, f.second);
    if (p.first - 1 >= 0 && !used.count({p.first - 1, p.second}) &&
        a[p.first - 1][p.second] == '.') {
      used.insert({p.first - 1, p.second});
      q.push({{p.first - 1, p.second}, f.second + 1});
    }
    if (p.first + 1 < h && !used.count({p.first + 1, p.second}) &&
        a[p.first + 1][p.second] == '.') {
      used.insert({p.first + 1, p.second});
      q.push({{p.first + 1, p.second}, f.second + 1});
    }
    if (p.second - 1 >= 0 && !used.count({p.first, p.second - 1}) &&
        a[p.first][p.second - 1] == '.') {
      used.insert({p.first, p.second - 1});
      q.push({{p.first, p.second - 1}, f.second + 1});
    }
    if (p.second + 1 >= 0 && !used.count({p.first, p.second + 1}) &&
        a[p.first][p.second + 1] == '.') {
      used.insert({p.first, p.second + 1});
      q.push({{p.first, p.second + 1}, f.second + 1});
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  cin >> h >> w;
  vector<pair<int, int>> vp;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> a[i][j];
      if (a[i][j] == '.') vp.push_back({i, j});
    }
  }
  int ans = 0;
  for (int i = 0; i < vp.size(); i++) {
    for (int j = i + 1; j < vp.size(); j++) {
      pair<int, int> x = vp[i], y = vp[j];
      used.clear();
      way = INF;
      bfs(x, y);
      if (way != INF) ans = max(ans, way);
    }
  }
  cout << ans;
}
