#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = 1000000007;
const int N = 100005;
bool u[N + N];
int f[N], dp[N], x[N], a[N], L[N], R[N];
vector<int> e[N * 3];
int main() {
  int n, m, i, j;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (i = 1; i <= m; i++) {
    scanf("%d", &x[i]);
    u[x[i]] = true;
  }
  sort(a + 1, a + n + 1);
  sort(x + 1, x + m + 1);
  for (i = 1; i <= n; i++) e[a[i] - i + N].push_back(i);
  L[1] = 1;
  for (i = 2; i <= n; i++) {
    if (a[i] == a[i - 1] + 1)
      L[i] = L[i - 1];
    else
      L[i] = i;
  }
  R[n] = n;
  for (i = n - 1; i > 0; i--) {
    if (a[i] == a[i + 1] - 1)
      R[i] = R[i + 1];
    else
      R[i] = i;
  }
  int rd = 1, pf = 0;
  for (i = 1; i <= n; i++) {
    while (rd <= m && x[rd] <= a[i]) rd++;
    dp[i] = f[i] = dp[i - 1];
    for (j = 1; j < rd; j++) {
      int v = x[j] - i;
      for (int h = e[v + N].size() - 1; h >= 0; h--) {
        int z = e[v + N][h];
        f[z]++;
        if (pf < f[z]) pf = f[z];
      }
    }
    if (R[i] == i) {
      for (j = rd - 1; j > 0; j--) {
        int ds = a[i] - x[j];
        if (i - 1 < ds) break;
        int p = L[i - ds];
        int tmp = dp[p - 1] + rd - j;
        if (f[i] < tmp) f[i] = tmp;
      }
      if (dp[i] < pf) dp[i] = pf;
      if (dp[i] < f[i]) dp[i] = f[i];
    }
    if (pf < f[i]) pf = f[i];
  }
  printf("%d\n", dp[n]);
  return 0;
}
