#include <bits/stdc++.h>
using namespace std;
typedef struct data {
  int x;
  int y;
} data;
int ans[21][21];
int h, w;
int isvalid(int x, int y) {
  if (x < h && y < w && x >= 0 && y >= 0 && ans[x][y]) return 1;
  return 0;
}
int bfs(data source) {
  if (!isvalid(source.x, source.y)) {
    return -1;
  }
  int visited[21][21] = {0};
  queue<pair<data, int>> q;
  q.push(make_pair(source, 0));
  int ans = 0;
  while (!q.empty()) {
    pair<data, int> c = q.front();
    data p = c.first;
    int row = p.x;
    int col = p.y;
    int val = c.second;
    q.pop();
    ans = max(ans, val);
    if (isvalid(row + 1, col) && !visited[row + 1][col]) {
      visited[row + 1][col] = 1;
      data temp;
      temp.x = row + 1;
      temp.y = col;
      q.push(make_pair(temp, val + 1));
    }
    if (isvalid(row - 1, col) && !visited[row - 1][col]) {
      visited[row - 1][col] = 1;
      data temp;
      temp.x = row - 1;
      temp.y = col;
      q.push(make_pair(temp, val + 1));
    }
    if (isvalid(row, col + 1) && !visited[row][col + 1]) {
      visited[row][col + 1] = 1;
      data temp;
      temp.x = row;
      temp.y = col + 1;
      q.push(make_pair(temp, val + 1));
    }
    if (isvalid(row, col - 1) && !visited[row][col - 1]) {
      visited[row][col - 1] = 1;
      data temp;
      temp.x = row;
      temp.y = col - 1;
      q.push(make_pair(temp, val + 1));
    }
  }
  return ans;
}
int main() {
  int i, j;
  scanf("%d%d", &h, &w);
  char a[21][21];
  for (i = 0; i < h; i++) {
    scanf("%s", a[i]);
    for (j = 0; j < w; j++) {
      if (a[i][j] == '#') {
        ans[i][j] = 0;
      } else
        ans[i][j] = 1;
    }
  }
  data source;
  int fin = -1;
  for (i = 0; i < h; i++) {
    for (j = 0; j < w; j++) {
      source.x = i;
      source.y = j;
      int ans1 = bfs(source);
      if (ans1 != -1) fin = max(fin, ans1);
    }
  }
  printf("%d\n", fin);
  return 0;
}
