#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")
using namespace std;
const long double PI = acos(-1);
const int MOD = 1000000007;
const int FMOD = 998244353;
const long double eps = 1e-9;
mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count());
void solve();
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);
  int t = 1;
  for (int testcase = 1; testcase < t + 1; testcase++) {
    solve();
  }
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}
const int MAXN = 20;
int n, m;
vector<string> grid;
int dist[MAXN][MAXN], vis[MAXN][MAXN];
int dx[] = {-1, 1, 0, 0}, dy[] = {0, 0, 1, -1};
bool valid(int x, int y) {
  return (0 <= x and x < n and 0 <= y and y < m and grid[x][y] == '.');
}
int bfs(int rootx, int rooty) {
  queue<pair<int, int> > q;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      dist[i][j] = 10000;
      vis[i][j] = 0;
    }
  dist[rootx][rooty] = 0;
  q.push(make_pair(rootx, rooty));
  while (!q.empty()) {
    auto node = q.front();
    q.pop();
    for (int i = 0; i < 4; i++) {
      int newx = node.first + dx[i], newy = node.second + dy[i];
      if (valid(newx, newy) and !vis[newx][newy]) {
        vis[newx][newy] = 1;
        dist[newx][newy] = 1 + dist[node.first][node.second];
        q.push(make_pair(newx, newy));
      }
    }
  }
  int ret = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (valid(i, j)) ret = max(ret, dist[i][j]);
  return ret;
}
void solve() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    grid.push_back(s);
  }
  int ans = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (valid(i, j)) ans = max(ans, bfs(i, j));
  cout << (ans) << endl;
}
