#include <bits/stdc++.h>
using namespace std;
bool visit[20][20], grid[20][20];
long long n, m;
long long bfs(long long i, long long j, long long dist) {
  visit[i][j] = 1;
  long long ans = 0;
  queue<pair<pair<long long, long long>, long long> > Q;
  Q.push({{i, j}, dist});
  while (Q.size() != 0) {
    pair<pair<long long, long long>, long long> p = Q.front();
    Q.pop();
    i = p.first.first;
    j = p.first.second;
    visit[i][j] = 1;
    ans = max(ans, p.second);
    if (i + 1 < n)
      if (!visit[i + 1][j] && !grid[i + 1][j])
        Q.push({{i + 1, j}, p.second + 1});
    if (j + 1 < m)
      if (!visit[i][j + 1] && !grid[i][j + 1])
        Q.push({{i, j + 1}, p.second + 1});
    if (i - 1 >= 0)
      if (!visit[i - 1][j] && !grid[i - 1][j])
        Q.push({{i - 1, j}, p.second + 1});
    if (j - 1 >= 0)
      if (!visit[i][j - 1] && !grid[i][j - 1])
        Q.push({{i, j - 1}, p.second + 1});
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  srand(time(NULL));
  ;
  long long k, z = 0, x, y, ans = 0, j, t = 0, c = 0, i;
  cin >> n >> m;
  string s;
  for (i = 0; i < n; i++) {
    cin >> s;
    for (j = 0; j < m; j++) {
      grid[i][j] = (s[j] == '#');
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (grid[i][j] == 1) continue;
      memset((visit), (0), sizeof((visit)));
      ans = max(ans, bfs(i, j, 0));
    }
  }
  cout << ans;
}
