#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long power(long long a, long long b) {
  if (b == 0) return 1;
  long long res = power(a, b / 2);
  if (b & 1)
    return res * res * a;
  else
    return res * res;
}
long long mat[20][20];
bool isValid(long long x, long long y, long long n, long long m) {
  if (x >= 0 && x <= n - 1 && y >= 0 && y <= m - 1 && mat[x][y] == 1)
    return true;
  else
    return false;
}
long long bfs(pair<long long, long long> src, pair<long long, long long> des,
              long long n, long long m) {
  queue<pair<long long, long long>> qu;
  qu.push(src);
  long long cost[n][m];
  bool vis[n][m];
  memset(cost, 0, sizeof(cost));
  memset(vis, false, sizeof(vis));
  long long itr = 0;
  while (!qu.empty()) {
    pair<long long, long long> p = qu.front();
    long long x = p.first, y = p.second;
    qu.pop();
    vis[x][y] = true;
    if (isValid(x, y - 1, n, m) && !vis[x][y - 1]) {
      qu.push({x, y - 1});
      cost[x][y - 1] = cost[x][y] + 1;
    }
    if (isValid(x, y + 1, n, m) && !vis[x][y + 1]) {
      qu.push({x, y + 1});
      cost[x][y + 1] = cost[x][y] + 1;
    }
    if (isValid(x - 1, y, n, m) && !vis[x - 1][y]) {
      qu.push({x - 1, y});
      cost[x - 1][y] = cost[x][y] + 1;
    }
    if (isValid(x + 1, y, n, m) && !vis[x + 1][y]) {
      qu.push({x + 1, y});
      cost[x + 1][y] = cost[x][y] + 1;
    }
  }
  return cost[des.first][des.second];
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long n, m;
  cin >> n >> m;
  vector<pair<long long, long long>> vp;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      char c;
      cin >> c;
      if (c == '.') {
        vp.push_back({i, j});
        mat[i][j] = 1;
      } else {
        mat[i][j] = 0;
      }
    }
  }
  long long ans = 0;
  for (long long i = 0; i < vp.size(); i++) {
    pair<long long, long long> src = vp[i];
    for (long long j = i; j < vp.size(); j++) {
      pair<long long, long long> des = vp[j];
      long long ct = bfs(src, des, n, m);
      ans = max(ans, ct);
    }
  }
  cout << ans;
  return 0;
}
