#include <bits/stdc++.h>
using namespace std;
int solve(int arr[20][20], int x, int y, int h, int w) {
  int vis[20][20];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      vis[i][j] = -1;
    }
  }
  queue<pair<int, int>> q;
  q.push(make_pair(x, y));
  int len = 0;
  int i, j;
  while (!q.empty()) {
    i = q.front().first;
    j = q.front().second;
    q.pop();
    if ((i + 1 >= 0 && i + 1 < h) && (j >= 0 && j < w) && arr[i + 1][j] == 1 &&
        vis[i + 1][j] == -1) {
      vis[i + 1][j] = vis[i][j] + 1;
      len = max(len, vis[i + 1][j]);
      q.push(make_pair(i + 1, j));
    }
    if ((i - 1 >= 0 && i - 1 < h) && (j >= 0 && j < w) && arr[i - 1][j] == 1 &&
        vis[i - 1][j] == -1) {
      vis[i - 1][j] = vis[i][j] + 1;
      len = max(len, vis[i - 1][j]);
      q.push(make_pair(i - 1, j));
    }
    if ((i >= 0 && i < h) && (j + 1 >= 0 && j + 1 < w) && arr[i][j + 1] == 1 &&
        vis[i][j + 1] == -1) {
      vis[i][j + 1] = vis[i][j] + 1;
      len = max(len, vis[i][j + 1]);
      q.push(make_pair(i, j + 1));
    }
    if ((i >= 0 && i < h) && (j - 1 >= 0 && j - 1 < w) && arr[i][j - 1] == 1 &&
        vis[i][j - 1] == -1) {
      vis[i][j - 1] = vis[i][j] + 1;
      len = max(len, vis[i][j - 1]);
      q.push(make_pair(i, j - 1));
    }
  }
  return len;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int h, w;
  cin >> h >> w;
  int i, j;
  int arr[20][20];
  char ch;
  for (i = 0; i < h; i++) {
    for (j = 0; j < w; j++) {
      cin >> ch;
      if (ch == '.') {
        arr[i][j] = 1;
      } else {
        arr[i][j] = 0;
      }
    }
  }
  int maxlen = 0;
  for (i = 0; i < h; i++) {
    for (j = 0; j < w; j++) {
      if (arr[i][j] == 1) {
        maxlen = max(maxlen, solve(arr, i, j, h, w));
      }
    }
  }
  cout << maxlen + 1;
  return 0;
}
