#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int, int>;
vector<char> dx = {0, -1, 0, 1};
vector<char> dy = {-1, 0, 1, 0};
int H, W;
int dist[30][30];
void dfs(vector<string> &S, int y, int x) {
  for (int dir = 0; dir < 4; dir++) {
    int ny = y + dy.at(dir);
    int nx = x + dx.at(dir);
    if (ny < 0 || nx < 0 || ny >= H || nx >= W) continue;
    if (dist[ny][nx] != -1) {
      if (dist[ny][nx] < dist[y][x] + 1) continue;
    }
    if (S.at(ny).at(nx) == '#') continue;
    dist[ny][nx] = dist[y][x] + 1;
    dfs(S, ny, nx);
  }
}
int main() {
  int ans = 0;
  cin >> H >> W;
  vector<string> S(H);
  for (ll i = 0; i < (ll)(H); i++) cin >> S.at(i);
  for (ll i = 0; i < (ll)(H); i++)
    for (ll j = 0; j < (ll)(W); j++) {
      if (S.at(i).at(j) == '#') continue;
      for (ll k = 0; k < (ll)(H); k++)
        for (ll l = 0; l < (ll)(W); l++) dist[k][l] = -1;
      dist[i][j] = 0;
      dfs(S, i, j);
      int tmp = 0;
      for (ll i = 0; i < (ll)(H); i++)
        for (ll j = 0; j < (ll)(W); j++) tmp = max(tmp, dist[i][j]);
      ans = max(ans, tmp);
    }
  cout << ans << endl;
  return 0;
}
