#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int n, m;
char c[25][25];
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};
int vis[23][23];
int mx = 0;
void bfs(int x, int y) {
  queue<pair<pair<int, int>, int> > q;
  q.push(make_pair(make_pair(x, y), 0));
  while (!q.empty()) {
    pair<pair<int, int>, int> p;
    p = q.front();
    q.pop();
    for (int i = 0; i < 4; i++) {
      int ax = p.first.first + dx[i];
      int ay = p.first.second + dy[i];
      if (ax >= 0 && ax < n && ay >= 0 && ay < m && c[ax][ay] == '.' &&
          !vis[ax][ay]) {
        vis[ax][ay] = p.second + 1;
        mx = max(mx, vis[ax][ay]);
        q.push(make_pair(make_pair(ax, ay), vis[ax][ay]));
      }
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> c[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (c[i][j] == '#') continue;
      bfs(i, j);
      memset(vis, 0, sizeof(vis));
    }
  }
  cout << mx << endl;
  return 0;
}
