#include <bits/stdc++.h>
using namespace std;
string maze[25];
int fx[] = {-1, 1, 0, 0};
int fy[] = {0, 0, -1, 1};
int h, w;
int visit[25][25], cost[25][25];
long bfs(int tx, int ty) {
  int i, j, x, y;
  long temp;
  queue<pair<int, int>> q;
  visit[tx][ty] = 1;
  cost[tx][ty] = 0;
  q.push(make_pair(tx, ty));
  while (!q.empty()) {
    pair<int, int> p;
    p = q.front();
    q.pop();
    for (int k = 0; k < 4; k++) {
      x = p.first + fx[k];
      y = p.second + fy[k];
      if (x >= 0 && x < h && y >= 0 && y < w && visit[x][y] != -1 &&
          maze[x][y] == '.') {
        visit[x][y] = -1;
        cost[x][y] = cost[p.first][p.second] + 1;
        q.push(make_pair(x, y));
        temp = max(temp, (long)cost[x][y]);
      }
    }
  }
  return temp;
}
int main() {
  int i, j;
  long ans = 0;
  cin >> h >> w;
  for (i = 0; i < h; i++) {
    cin >> maze[i];
  }
  for (i = 0; i < h; i++) {
    for (j = 0; j < w; j++) {
      if (maze[i][j] == '.') {
        memset(visit, 0, sizeof(visit));
        memset(cost, 0, sizeof(cost));
        ans = max(ans, bfs(i, j));
      }
    }
  }
  cout << ans << endl;
  return 0;
}
