#include <bits/stdc++.h>
const int maxn = 300009, mod = 1e9 + 7, inf = 0x3f3f3f3f;
int Read() {
  int x(0), f(1);
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 3) + (x << 1) + c - '0';
    c = getchar();
  }
  return x * f;
}
int n, m;
int a[maxn], b[maxn], visit[maxn], sum[maxn], f[maxn], g[maxn], L[maxn],
    R[maxn];
int Calc(int l, int r) { return sum[r] - sum[l - 1]; }
int main() {
  n = Read();
  m = Read();
  for (int i = 1; i <= n; ++i) a[i] = Read();
  std::sort(a + 1, a + 1 + n);
  for (int i = 1; i <= m; ++i) b[i] = Read(), ++sum[b[i]];
  std::sort(b + 1, b + 1 + m);
  for (int i = 1; i <= 200000; ++i) sum[i] += sum[i - 1];
  a[0] = -inf;
  a[n + 1] = inf;
  for (int i = 1; i <= n; ++i) {
    if (a[i] == a[i - 1] + 1)
      L[i] = L[i - 1];
    else
      L[i] = i;
  }
  for (int i = n; i >= 1; --i) {
    if (a[i] == a[i + 1] - 1)
      R[i] = R[i + 1];
    else
      R[i] = i;
  }
  for (int i = 1; i <= n; ++i) {
    f[i] = std::max(f[i], f[i - 1] + Calc(a[i], a[i]));
    g[i] = std::max(g[i], f[i - 1] + Calc(a[i], a[i]));
    for (int j = 1; j <= m; ++j) {
      int len(abs(b[j] - a[i]));
      if (b[j] <= a[i] && len < i) {
        g[i] = std::max(g[i], f[L[i - len] - 1] + Calc(b[j], a[i]));
      } else if (len <= n - i) {
        f[R[i + len]] = std::max(f[R[i + len]], g[i] + Calc(a[i] + 1, b[j]));
      }
    }
    f[i] = std::max(f[i], g[i]);
  }
  printf("%d\n", f[n]);
  return 0;
}
