#include <bits/stdc++.h>
using namespace std;
long long int solve(char a[20][20], int h, int w, int x, int y) {
  int vis[20][20];
  memset(vis, 0, sizeof(vis));
  queue<tuple<int, int, long long int>> pt;
  pt.push(make_tuple(x, y, 0));
  long long int ans = 0;
  while (!pt.empty()) {
    tuple<int, int, int> t = pt.front();
    pt.pop();
    pair<int, int> p = make_pair(get<0>(t), get<1>(t));
    if (!vis[p.first][p.second] && a[p.first][p.second] == '.') {
      long long int f = get<2>(t);
      ans = max(ans, f);
      vis[p.first][p.second] = 1;
      if (p.first + 1 < h) {
        pt.push({p.first + 1, p.second, get<2>(t) + 1});
      }
      if (p.first - 1 > -1) {
        pt.push({p.first - 1, p.second, get<2>(t) + 1});
      }
      if (p.second + 1 < w) {
        pt.push({p.first, p.second + 1, get<2>(t) + 1});
      }
      if (p.second - 1 > -1) {
        pt.push({p.first, p.second - 1, get<2>(t) + 1});
      }
    }
  }
  return ans;
}
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  while (t--) {
    int h, w;
    cin >> h >> w;
    char a[20][20];
    for (int i = 0; i < h; i++)
      for (int j = 0; j < w; j++) cin >> a[i][j];
    long long int ans = 0;
    for (int i = 0; i < h; i++)
      for (int j = 0; j < h; j++)
        if (a[i][j] == '.') ans = max(ans, solve(a, h, w, i, j));
    cout << ans << "\n";
  }
  return 0;
}
