#include <bits/stdc++.h>
using namespace std;
const long long int maxn = 21;
const long long int INF = 4e18;
long long int nodeno[maxn][maxn];
vector<long long int> adj_list[maxn * maxn];
bool visited[maxn * maxn];
long long int level[maxn * maxn];
void assign_nodeno(long long int h, long long int w) {
  long long int k = 1;
  for (long long int i = 0; i < h; i++) {
    for (long long int j = 0; j < w; j++) {
      nodeno[i][j] = k;
      k++;
    }
  }
}
void bfs(long long int s) {
  visited[s] = true;
  queue<long long int> q;
  q.push(s);
  level[s] = 0;
  while (!q.empty()) {
    long long int x = q.front();
    q.pop();
    for (auto it : adj_list[x]) {
      if (!visited[it]) {
        level[it] = level[x] + 1;
        visited[it] = true;
        q.push(it);
      }
    }
  }
}
void solve() {
  long long int h, w;
  cin >> h >> w;
  assign_nodeno(h, w);
  memset(visited, false, sizeof(visited));
  memset(visited, 0, sizeof(level));
  char g[maxn][maxn];
  for (long long int i = 0; i < h; i++) {
    for (long long int j = 0; j < w; j++) {
      cin >> g[i][j];
    }
  }
  for (long long int i = 0; i < h; i++) {
    for (long long int j = 0; j < w; j++) {
      if (i != 0) {
        if (g[i - 1][j] != '#')
          adj_list[nodeno[i][j]].push_back(nodeno[i - 1][j]);
      }
      if (i != h - 1) {
        if (g[i + 1][j] != '#')
          adj_list[nodeno[i][j]].push_back(nodeno[i + 1][j]);
      }
      if (j != 0) {
        if (g[i][j - 1] != '#')
          adj_list[nodeno[i][j]].push_back(nodeno[i][j - 1]);
      }
      if (j != w - 1) {
        if (g[i][j + 1] != '#')
          adj_list[nodeno[i][j]].push_back(nodeno[i][j + 1]);
      }
    }
  }
  long long int ans = 0;
  for (long long int p = 0; p < h; p++) {
    for (long long int q = 0; q < w; q++) {
      if (g[p][q] != '#') {
        bfs(nodeno[p][q]);
        for (long long int j = 1; j <= h * w; j++) {
          ans = max(ans, level[j]);
        }
        memset(level, 0, sizeof(level));
        memset(visited, 0, sizeof(visited));
      }
    }
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int T = 1, p = 0;
  do {
    solve();
    p++;
  } while (p < T);
  return 0;
}
