#include <bits/stdc++.h>
#pragma GCC optimize(3, "Ofast", "inline")
using namespace std;
long long qpow(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) res = res * a;
    a = a * a;
    b >>= 1;
  }
  return res;
}
long long qpow(long long a, long long b, long long mod) {
  long long res = 1;
  while (b) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return res;
}
long long inv(long long a, long long mod) { return qpow(a, mod - 2, mod); }
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 * b / gcd(a, b); }
template <typename T>
inline void read(T &x) {
  x = 0;
  T f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
  x *= f;
}
template <typename T>
inline void write(T x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
const double eps = 1e-10;
const long long inf = 0x3f3f3f3f, base = 137, mod = 1e9 + 7;
const int N = 2e5 + 5, M = 2e3 + 5, S = 1e6 + 5;
int a[N], b[N];
int dp[N];
int sum[N];
int L[N], R[N];
void solve() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= m; i++) scanf("%d", &b[i]);
  sort(a + 1, a + 1 + n);
  sort(b + 1, b + 1 + m);
  a[0] = -1, a[n + 1] = -1;
  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 <= m; i++) {
    sum[b[i]]++;
  }
  for (int i = 1; i <= 200000; i++) sum[i] += sum[i - 1];
  for (int i = 1; i <= n; i++) {
    dp[i] = max(dp[i], dp[i - 1]);
    int Max;
    if (L[i] == i)
      Max = dp[i - 1] + sum[a[i]] - sum[a[i] - 1];
    else
      Max = -10000000;
    dp[i] = max(dp[i], Max);
    for (int l = 1; b[l] <= a[i] && l <= m; l++)
      if (i - (a[i] - b[l]) >= 1) {
        dp[i] = max(dp[i],
                    dp[L[i - (a[i] - b[l])] - 1] + sum[a[i]] - sum[b[l] - 1]);
        Max =
            max(Max, dp[L[i - (a[i] - b[l])] - 1] + sum[a[i]] - sum[b[l] - 1]);
      }
    for (int r = m; b[r] >= a[i] && r; r--)
      if (i + b[r] - a[i] <= n)
        dp[R[i + b[r] - a[i]]] =
            max(dp[R[i + b[r] - a[i]]], Max + sum[b[r]] - sum[a[i]]);
  }
  cout << dp[n] << endl;
}
int main() {
  int T = 1;
  while (T--) {
    solve();
  }
}
