#include <bits/stdc++.h>
using namespace std;
char mat[20][20];
void run(int n, int m, int i, int j, int i2, int j2, int *at, int k) {
  if (i == i2 && j == j2) {
    if (*at > k) {
      *at = k;
    }
    return;
  } else if (i < 0 || i >= n || j < 0 || j >= m || mat[i][j] == '#') {
    return;
  }
  char aux = mat[i][j];
  mat[i][j] = '#';
  run(n, m, i + 1, j, i2, j2, at, k + 1);
  run(n, m, i - 1, j, i2, j2, at, k + 1);
  run(n, m, i, j + 1, i2, j2, at, k + 1);
  run(n, m, i, j - 1, i2, j2, at, k + 1);
  mat[i][j] = aux;
}
int main() {
  int n, m, ans = 0, at = INT_MAX;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> mat[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      for (int k = n - 1; k >= 0; k--) {
        for (int l = n - 1; l >= 0; l--) {
          at = INT_MAX;
          run(n, m, i, j, k, l, &at, 0);
          if (at > ans && at != INT_MAX) {
            ans = at;
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
