#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y, long long m) {
  long long r = 1;
  for (; y; y >>= 1) {
    if (y & 1) r = r * x % m;
    x = x * x % m;
  }
  return r;
}
const long long mod = 1e9 + 7;
const long double pi = 3.14159265358979;
int h, w, arr[23][23], visited[24][24], level[24][24];
int check(int i, int j) {
  if (i < 0 || j < 0 || i >= h || j >= w || arr[i][j] == 0) return 0;
  return 1;
}
int r[4] = {0, 1, -1, 0};
int c[4] = {1, 0, 0, -1};
int dfs(int x, int y) {
  memset((visited), (0), sizeof((visited)));
  memset((level), (0), sizeof((level)));
  queue<int> q;
  q.push(x);
  q.push(y);
  int k = 0;
  while (!q.empty()) {
    int a = q.front();
    q.pop();
    int b = q.front();
    q.pop();
    visited[a][b] = 1;
    for (int i = 0; i < 4; i++) {
      int new_x = a + r[i];
      int new_y = b + c[i];
      if (check(new_x, new_y) && !visited[new_x][new_y]) {
        q.push(new_x);
        q.push(new_y);
        level[new_x][new_y] = level[a][b] + 1;
        k = max(k, level[new_x][new_y]);
      }
    }
  }
  return k;
}
int run_test() {
  int k;
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      char t;
      cin >> t;
      if (t == '#')
        arr[i][j] = 0;
      else {
        arr[i][j] = 1;
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (arr[i][j] == 1) {
        k = dfs(i, j);
        ans = max(k, ans);
      }
    }
  }
  cout << ans;
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  srand(time(NULL));
  ;
  long long t;
  t = 1;
  while (t--) {
    run_test();
  }
}
