#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> v(22, vector<int>(22, -1));
vector<vector<char>> grid(22, vector<char>(22, '#'));
int dist(int h, int w) {
  vector<vector<int>> hoge(22, vector<int>(22, 9999));
  hoge[h + 1][w + 1] = 0;
  pair<int, int> now = make_pair(h + 1, w + 1);
  queue<pair<int, int>> q;
  q.push(now);
  while (!q.empty()) {
    now = q.front();
    q.pop();
    if (grid[now.first + 1][now.second] == '.' &&
        hoge[now.first + 1][now.second] > hoge[now.first][now.second]) {
      hoge[now.first + 1][now.second] = hoge[now.first][now.second] + 1;
      q.push(make_pair(now.first + 1, now.second));
    }
    if (grid[now.first - 1][now.second] == '.' &&
        hoge[now.first - 1][now.second] > hoge[now.first][now.second]) {
      hoge[now.first - 1][now.second] = hoge[now.first][now.second] + 1;
      q.push(make_pair(now.first - 1, now.second));
    }
    if (grid[now.first][now.second + 1] == '.' &&
        hoge[now.first][now.second + 1] > hoge[now.first][now.second]) {
      hoge[now.first][now.second + 1] = hoge[now.first][now.second] + 1;
      q.push(make_pair(now.first, now.second + 1));
    }
    if (grid[now.first][now.second - 1] == '.' &&
        hoge[now.first][now.second - 1] > hoge[now.first][now.second]) {
      hoge[now.first][now.second - 1] = hoge[now.first][now.second] + 1;
      q.push(make_pair(now.first, now.second - 1));
    }
  }
  int ans = 0;
  for (int i = 1; i < 21; ++i) {
    for (int j = 1; j < 21; ++j) {
      if (hoge[i][j] != 9999) {
        ans = max(ans, hoge[i][j]);
      }
    }
  }
  return ans;
}
int main() {
  int h, w;
  cin >> h >> w;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cin >> grid[i + 1][j + 1];
    }
  }
  int ans = 0;
  for (int i = 0; i < 20; ++i) {
    for (int j = 0; j < 20; ++j) {
      if (grid[i + 1][j + 1] == '.') {
        ans = max(ans, dist(i, j));
      }
    }
  }
  cout << ans << endl;
  return 0;
}
