#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using graph = vector<vector<int>>;
const ll mod = pow(10, 9) + 7;
const int INF = 1e9;
const ll LINF = 1e18;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
char f[22][22] = {"#"};
int H, W, ans = 0;
void dfs(int sx, int sy) {
  bool seen[22][22] = {false};
  int dist[22][22] = {-1};
  dist[sx][sy] = 0;
  queue<pair<int, int>> que;
  que.push(make_pair(sx, sy));
  while (!que.empty()) {
    pair<int, int> current_pos = que.front();
    int x = current_pos.first;
    int y = current_pos.second;
    que.pop();
    for (int i = 0; i < (int)4; i++) {
      int nx = x + dx[i];
      int ny = y + dy[i];
      if (f[nx][ny] == '#') continue;
      if (seen[nx][ny] == false) {
        que.push(make_pair(nx, ny));
        dist[nx][ny] = dist[x][y] + 1;
        ans = max(ans, dist[nx][ny]);
      }
    }
  }
}
int main() {
  cin >> H >> W;
  for (int i = 1; i <= (int)H; i++) {
    for (int j = 1; j <= (int)W; j++) {
      cin >> f[i][j];
    }
  }
  for (int i = 1; i <= (int)H; i++) {
    for (int j = 1; j <= (int)W; j++) {
      if (f[i][j] == '.') {
        dfs(i, j);
      }
    }
  }
  cout << ans << endl;
}
