#include <bits/stdc++.h>
int H, W;
int input[20][20];
using namespace std;
void show() {
  printf("SHOW\n");
  for (int i = 0; i < (int)(H); ++i) {
    for (int j = 0; j < (int)(W); ++j) {
      printf("%03d ", input[i][j]);
    }
    printf("\n");
  }
}
int cleanup() {
  int ret = -2;
  for (int i = 0; i < (int)(H); ++i) {
    for (int j = 0; j < (int)(W); ++j) {
      if (ret < input[i][j]) ret = input[i][j];
      if (input[i][j] != -1) input[i][j] = -2;
    }
  }
  return ret;
}
int search_longest(int i, int j, int current) {
  if (i < 0 || j < 0 || i >= H || j >= W) return current - 1;
  if (input[i][j] == -1) return current - 1;
  if (input[i][j] != -2 && current > input[i][j]) {
    return current;
  }
  input[i][j] = current;
  vector<pair<int, int>> p{{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
  int ret = 0;
  for (auto itr : p) {
    ret = max(ret, search_longest(i + itr.first, j + itr.second, current + 1));
  }
  return ret;
}
int main() {
  cin >> H >> W;
  for (int i = 0; i < (int)(H); ++i) {
    for (int j = 0; j < (int)(W); ++j) {
      char n;
      cin >> n;
      input[i][j] = n == '#' ? -1 : -2;
    }
  }
  int longest = -1;
  for (int i = 0; i < (int)(H); ++i) {
    for (int j = 0; j < (int)(W); ++j) {
      search_longest(i, j, 0);
      int ret = cleanup();
      longest = max(ret, longest);
    }
  }
  cout << longest << endl;
  return 0;
}
