#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6;
int a[maxn], b[maxn], head[maxn], f[maxn], g[maxn];
int i, j, n, m, now;
void update(int &a, int b) { a = max(a, b); }
int main() {
  scanf("%d %d", &n, &m);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (i = 1; i <= m; i++) scanf("%d", &b[i]);
  sort(a + 1, a + n + 1);
  sort(b + 1, b + m + 1);
  for (i = now = 1; i <= n; i++) {
    head[i] = i > 1 && a[i] == a[i - 1] + 1 ? head[i - 1] : i;
    while (now <= m && b[now] <= a[i]) now++;
    update(f[i], g[head[i] - 1]);
    for (j = now - 1; j > 0 && a[i] - b[j] + 1 <= i; j--)
      update(f[i], g[head[i - (a[i] - b[j])] - 1] + now - j);
    update(g[i], f[i]);
    update(g[i], g[i - 1]);
    for (j = now; j <= m && b[j] - a[i] <= n - i; j++)
      update(g[i + b[j] - a[i]], f[i] + j - now + 1);
  }
  printf("%d\n", g[n]);
  return 0;
}
