#include <bits/stdc++.h>
using namespace std;
const long long N = 20;
const long long row[4] = {0, -1, 0, 1};
const long long col[4] = {-1, 0, 1, 0};
long long h, w;
long long vis[N][N];
long long cost[N][N][N][N];
string s[N];
long long can(long long x, long long y) {
  if (x < 0 || x >= h || y < 0 || y >= w) return 0;
  if (s[x][y] == '#') return 0;
  return 1;
}
void shortest_path(long long beg_row, long long beg_col) {
  memset(vis, 0, sizeof vis);
  queue<pair<long long, long long>> q;
  queue<long long> deep;
  q.push({beg_row, beg_col});
  deep.push(0);
  while (!q.empty()) {
    long long cur_row = q.front().first;
    long long cur_col = q.front().second;
    long long cur_level = deep.front();
    deep.pop();
    q.pop();
    vis[cur_row][cur_col] = 1;
    cost[beg_row][beg_col][cur_row][cur_col] = cur_level;
    for (long long i = 0; i < 4; i++) {
      long long tar_row = row[i] + cur_row;
      long long tar_col = col[i] + cur_col;
      if (can(tar_row, tar_col) && vis[tar_row][tar_col] == 0) {
        q.push({tar_row, tar_col});
        deep.push(cur_level + 1);
      }
    }
  }
}
signed main() {
  ios_base ::sync_with_stdio(0);
  cin.tie();
  cout.tie();
  cout << fixed;
  cout << setprecision(15);
  srand(time(NULL));
  cin >> h >> w;
  for (long long i = 0; i < h; i++) {
    cin >> s[i];
  }
  for (long long i = 0; i < N; i++) {
    for (long long j = 0; j < N; j++) {
      for (long long ii = 0; ii < N; ii++) {
        for (long long jj = 0; jj < N; jj++) {
          cost[i][j][ii][jj] = INT_MAX;
        }
      }
    }
  }
  vector<pair<long long, long long>> v;
  for (long long i = 0; i < h; i++) {
    for (long long j = 0; j < w; j++) {
      if (s[i][j] == '#') continue;
      v.push_back({i, j});
    }
  }
  long long n = (long long)v.size();
  for (long long i = 0; i < n; i++) shortest_path(v[i].first, v[i].second);
  long long res = 0;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) {
      res = max(res, cost[v[i].first][v[i].second][v[j].first][v[j].second]);
    }
  }
  cout << res << "\n";
  return 0;
}
