#include <bits/stdc++.h>
using namespace std;
struct edge {
  long long to, cost;
};
const long long INF = 100000000000000000;
const long long INF2 = 9223372036854775807;
const long long MOD = 1000000007;
long long ceil2(long long a, long long b) {
  if (a % b == 0) {
    return a / b;
  } else {
    return a / b + 1;
  }
}
long long pow2(long long a, long long b) {
  long long r = 1;
  for (long long i = 1; i <= b; i++) {
    r *= a;
  }
  return r;
}
long long Log2(long long a) {
  long long t = 0;
  while (1) {
    if (a == 0 || a == 1) {
      break;
    }
    a /= 2;
    t++;
  }
  return t;
}
long long N, M;
char Maze[21][21];
long long D[21][21];
long long BFS(long long sx, long long sy, long long gx, long long gy) {
  queue<std::pair<long long, long long> > que;
  long long dx[] = {1, 0, -1, 0};
  long long dy[] = {0, 1, 0, -1};
  for (long long i = 0; i < (long long)(N); i++)
    for (long long j = 0; j < (long long)(M); j++) {
      D[i][j] = INF;
    }
  que.push(std::pair<long long, long long>(sx, sy));
  D[sx][sy] = 0;
  while (!que.empty()) {
    std::pair<long long, long long> p = que.front();
    que.pop();
    if (p.first == gx && p.second == gy) {
      break;
    }
    for (long long i = 0; i < 4; i++) {
      long long nx = p.first + dx[i];
      long long ny = p.second + dy[i];
      if (0 <= nx && nx < N && 0 <= ny && ny < M && Maze[nx][ny] != '#' &&
          D[nx][ny] == INF) {
        que.push(std::pair<long long, long long>(nx, ny));
        D[nx][ny] = D[p.first][p.second] + 1;
      }
    }
  }
  return D[gx][gy];
}
signed main() {
  cin >> N >> M;
  for (long long i = 0; i < (long long)(N); i++) {
    cin >> Maze[i];
  }
  long long d = 0;
  for (long long i = 0; i < (long long)(N); i++) {
    for (long long j = 0; j < (long long)(M); j++) {
      for (long long k = 0; k < (long long)(N); k++) {
        for (long long l = 0; l < (long long)(M); l++) {
          long long dis = BFS(i, j, k, l);
          if (dis != INF) {
            d = (((long long)(d) > (long long)(dis)) ? (d) : (dis));
          }
        }
      }
    }
  }
  cout << d << endl;
  return 0;
}
