#include <bits/stdc++.h>
using namespace std;
using namespace std;
long long int n, m;
void dfs1(pair<long long int, long long int> st, long long int vis[25][25],
          string grid[], long long int dist[25][25]) {
  long long int i = st.first;
  long long int j = st.second;
  queue<pair<long long int, long long int> > q;
  q.push(st);
  while (!q.empty()) {
    pair<long long int, long long int> th = q.front();
    q.pop();
    long long int i = th.first;
    long long int j = th.second;
    vis[i][j] = 1;
    if (i && grid[i - 1][j] == '.' && vis[i - 1][j] == 0) {
      dist[i - 1][j] = dist[i][j] + 1;
      q.push(make_pair(i - 1, j));
    }
    if (j && grid[i][j - 1] == '.' && vis[i][j - 1] == 0) {
      dist[i][j - 1] = dist[i][j] + 1;
      q.push(make_pair(i, j - 1));
    }
    if (j < m - 1 && grid[i][j + 1] == '.' && vis[i][j + 1] == 0) {
      dist[i][j + 1] = dist[i][j] + 1;
      q.push(make_pair(i, j + 1));
    }
    if (i < n - 1 && grid[i + 1][j] == '.' && vis[i + 1][j] == 0) {
      dist[i + 1][j] = dist[i][j] + 1;
      q.push(make_pair(i + 1, j));
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  string grid[25];
  for (int i = 0; i < n; ++i) {
    cin >> grid[i];
  }
  long long int dist[25][25];
  long long int vis[25][25];
  long long int ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      memset(vis, 0, sizeof(vis));
      memset(dist, -1, sizeof(dist));
      if (grid[i][j] == '.') {
        dist[i][j] = 0;
        dfs1(make_pair(i, j), vis, grid, dist);
        long long int ma = 0;
        for (int i1 = 0; i1 < n; ++i1) {
          for (int j1 = 0; j1 < m; ++j1) {
            ma = max(dist[i1][j1], ma);
          }
        }
        ans = max(ans, ma);
      }
    }
  }
  cout << ans << endl;
}
