#include <bits/stdc++.h>
using namespace std;
int a[25][25] = {0};
int n, m;
int d[4][2] = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}};
int bfs(int i, int j) {
  queue<pair<int, int> > q;
  int c = 0;
  int vis[25][25] = {0}, dis[25][25] = {0};
  q.push({i, j});
  vis[i][j] = 1;
  while (!q.empty()) {
    pair<int, int> el = q.front();
    int x = el.first, y = el.second;
    for (int f = 0; f < 4; f++) {
      int newdx = d[f][0] + x, newdy = d[f][1] + y;
      if (newdx < 0 || newdx >= n || newdy < 0 || newdy >= m) continue;
      if (!vis[newdx][newdy] && a[newdx][newdy] != -1) {
        vis[newdx][newdy] = 1;
        dis[newdx][newdy] = dis[x][y] + 1;
        c = max(c, dis[newdx][newdy]);
        q.push({newdx, newdy});
      }
    }
    q.pop();
  }
  return c;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  int q = 0;
  for (int i = 0; i < n; i++) {
    string c;
    cin >> c;
    for (int j = 0; j < m; j++) {
      if (c[j] == '#') a[i][j] = -1;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a[i][j] == -1) continue;
      q = max(q, bfs(i, j));
    }
  }
  cout << q << "\n";
  return 0;
}
