#include <bits/stdc++.h>
using namespace std;
string s[30];
bool vis[30][30];
int n, m;
int dir[4][2] = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}};
struct node {
  int x, y, t;
  node(int x, int y, int t) : x(x), y(y), t(t) {}
};
int mx = -1;
void bfs(int x, int y) {
  memset(vis, false, sizeof(vis));
  queue<node> q;
  q.push(node(x, y, 0));
  while (!q.empty()) {
    node now = q.front();
    q.pop();
    for (int j = 0; j < 4; ++j) {
      int xx = now.x + dir[j][0];
      int yy = now.y + dir[j][1];
      if (xx >= 0 && yy >= 0 && xx < n && yy < m && !vis[xx][yy] &&
          s[xx][yy] != '#') {
        vis[xx][yy] = true;
        q.push(node(xx, yy, now.t + 1));
        mx = max(mx, now.t + 1);
      }
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    cin >> s[i];
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      bfs(i, j);
    }
  }
  cout << mx << endl;
}
