#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long powmod(long long a, long long b, long long MOD) {
  if (a == 0ll) {
    return 0ll;
  }
  a %= MOD;
  long long ans = 1;
  while (b) {
    if (b & 1) {
      ans = ans * a % MOD;
    }
    a = a * a % MOD;
    b >>= 1;
  }
  return ans;
}
long long poww(long long a, long long b) {
  if (a == 0ll) {
    return 0ll;
  }
  long long ans = 1;
  while (b) {
    if (b & 1) {
      ans = ans * a;
    }
    a = a * a;
    b >>= 1;
  }
  return ans;
}
void Pv(const vector<int> &V) {
  int Len = int(V.size());
  for (int i = 0; i < Len; ++i) {
    printf("%d", V[i]);
    if (i != Len - 1) {
      printf(" ");
    } else {
      printf("\n");
    }
  }
}
void Pvl(const vector<long long> &V) {
  int Len = int(V.size());
  for (int i = 0; i < Len; ++i) {
    printf("%lld", V[i]);
    if (i != Len - 1) {
      printf(" ");
    } else {
      printf("\n");
    }
  }
}
inline long long readll() {
  long long tmp = 0, fh = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') fh = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar();
  return tmp * fh;
}
inline int readint() {
  int tmp = 0, fh = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') fh = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar();
  return tmp * fh;
}
const int maxn = 22;
const int inf = 0x3f3f3f3f;
char s[maxn][maxn];
int n, m;
int ans = 0;
bool vis[maxn][maxn];
bool vised[maxn][maxn][maxn][maxn];
struct node {
  int x, y;
  int step;
  node() {}
  node(int xx, int yy, int ss) {
    x = xx;
    y = yy;
    step = ss;
  }
};
queue<node> q;
int aid_x, aid_y;
int now;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
void bfs(int x, int y) {
  q.push(node(x, y, 0));
  vis[x][y] = 1;
  node temp;
  now = 0;
  while (!q.empty()) {
    temp = q.front();
    q.pop();
    if (temp.x == aid_x && temp.y == aid_y) {
      now = temp.step;
      break;
    }
    for (int i = 0; i < 4; ++i) {
      int tx = dx[i] + temp.x;
      int ty = dy[i] + temp.y;
      if (tx >= 1 && tx <= n && ty >= 1 && ty <= m && vis[tx][ty] == 0 &&
          s[tx][ty] == '.') {
        vis[tx][ty] = 1;
        q.push(node(tx, ty, temp.step + 1));
      }
    }
  }
  while (!q.empty()) q.pop();
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%s", s[i] + 1);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      for (int k = 1; k <= n; k++) {
        for (int z = 1; z <= m; z++) {
          if (vised[i][j][k][z] || vised[k][z][i][j]) {
            continue;
          }
          vised[i][j][k][z] = 1;
          vised[k][z][i][j] = 1;
          aid_x = k;
          aid_y = z;
          memset((vis), 0, sizeof((vis)));
          bfs(i, j);
          ans = max(ans, now);
        }
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
