#include <bits/stdc++.h>
const int NIL = -1;
const int MOD = 1000000007;
using namespace std;
int modinv(int a, int m) {
  int b = m, u = 1, v = 0;
  while (b) {
    int t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}
int pow(int x, int n) {
  int res = 1;
  while (n) {
    if (n & 1) res *= x;
    x *= x;
    n >>= 1;
  }
  return res;
}
int get_gcd(int a, int b) {
  while (1) {
    if (a < b) swap(a, b);
    if (b == 0) return a;
    a %= b;
  }
}
int get_lcm(int a, int b) { return a * b / get_gcd(a, b); }
bool chmin(int &a, int b) {
  if (a > b) {
    a = b;
    return true;
  } else
    return false;
}
bool chmax(int &a, int b) {
  if (a < b) {
    a = b;
    return true;
  } else
    return false;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
char S[20][20];
bool seen[20][20];
int H, W;
typedef struct {
  int y;
  int x;
  int count;
} Node;
int bfs(const int in_y, const int in_x) {
  for (int(i) = 0; (i) < (H); ++(i)) {
    for (int(j) = 0; (j) < (W); ++(j)) {
      seen[i][j] = false;
    }
  }
  queue<Node> que;
  const Node root = {in_y, in_x, 0};
  que.push(root);
  int max_count = 0;
  while (que.size() > 0) {
    auto r = que.front();
    que.pop();
    chmax(max_count, r.count);
    seen[r.y][r.x] = true;
    for (int(i) = 0; (i) < (4); ++(i)) {
      const int ny = r.y + dy[i];
      const int nx = r.x + dx[i];
      if (ny < 0 || ny >= H || nx < 0 || nx >= W) continue;
      if (seen[ny][nx] || S[ny][nx] == '#') continue;
      const Node next = {ny, nx, r.count + 1};
      que.push(next);
    }
  }
  return max_count;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> H >> W;
  for (int(i) = 0; (i) < (H); ++(i)) {
    for (int(j) = 0; (j) < (W); ++(j)) {
      cin >> S[i][j];
    }
  }
  int max_step = 0;
  for (int(i) = 0; (i) < (H); ++(i)) {
    for (int(j) = 0; (j) < (W); ++(j)) {
      if (S[i][j] == '#') continue;
      chmax(max_step, bfs(i, j));
    }
  }
  cout << max_step << endl;
  return 0;
}
