#include <bits/stdc++.h>
using namespace std;
void fastio() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
void input() {}
char grid[21][21];
int n, m;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int get_distance(int i, int j, int k, int l) {
  queue<pair<int, int>> que;
  que.push(make_pair(i, j));
  int dis = 0;
  bool vis[21][21];
  memset(vis, false, sizeof vis);
  while (!que.empty()) {
    int s = que.size();
    while (s--) {
      pair<int, int> p = que.front();
      que.pop();
      if (p.first == k && p.second == l) {
        return dis;
      }
      vis[p.first][p.second] = 1;
      for (int x = 0; x < 4; x++) {
        int newx = p.first + dx[x];
        int newy = p.second + dy[x];
        if (newx >= 0 && newx < n && newy >= 0 && newy < m &&
            grid[newx][newy] != '#' && !vis[newx][newy]) {
          que.push(make_pair(newx, newy));
        }
      }
    }
    dis++;
  }
  return dis;
}
int main() {
  fastio();
  int i, j, k, l, ans = 0;
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cin >> grid[i][j];
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      for (k = 0; k < n; k++) {
        for (l = 0; l < m; l++) {
          if (!((i == k) && (j == l)) && grid[i][j] != '#' &&
              grid[k][l] != '#') {
            int dis = get_distance(i, j, k, l);
            ans = max(ans, dis);
          }
        }
      }
    }
  }
  cout << ans;
  return 0;
}
