#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e9;
const int mod = 1e9 + 7;
const int oo = 1e9 + 7;
void IOS() { cin.tie()->sync_with_stdio(0); }
void FRE() {
  freopen(
      "PM"
      ".inp",
      "r", stdin);
  freopen(
      "PM"
      ".out",
      "w", stdout);
}
const int MAX_N = 1000010;
const int MAX_M = 1000010;
int n, m;
int A[MAX_N];
int B[MAX_N];
int L[MAX_N], R[MAX_N];
int sum[MAX_N];
int Dp[MAX_N];
void maximum(int &a, const int &b) {
  if (a < b) a = b;
}
void IN() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> A[i];
  }
  sort(A + 1, A + 1 + n);
  A[0] = A[1] - 1000;
  A[n + 1] = A[n] + 1000;
  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++) {
    cin >> B[i];
    sum[B[i]]++;
  }
  sort(B + 1, B + 1 + m);
  sum[0] = 0;
  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;
    maximum(Dp[i], MAX);
    for (int j = 1; B[j] <= A[i] && j <= m; j++) {
      if (i - (A[i] - B[j]) >= 1) {
        maximum(Dp[i],
                Dp[L[i - (A[i] - B[j])] - 1] + sum[A[i]] - sum[B[j] - 1]);
        maximum(MAX, Dp[L[i - (A[i] - B[j])] - 1] + sum[A[i]] - sum[B[j] - 1]);
      }
    }
    for (int j = m; j >= 1, A[i] <= B[j]; j--) {
      if (i + B[j] - A[i] <= n) {
        maximum(Dp[R[i + B[j] - A[i]]], MAX + sum[B[j]] - sum[A[i]]);
      }
    }
  }
  cout << Dp[n];
  return;
}
void OUT() { return; }
int main() {
  IOS();
  IN();
  OUT();
  return 0;
}
