#include <bits/stdc++.h>
using namespace std;
const int N(200010), M(2010);
int n, m, l;
int a[N], b[M], L[N], R[N], f[N], g[N], sum[N];
int main() {
  register int i, j;
  cin >> n >> m;
  for (i = 1; i <= n; ++i) cin >> a[i];
  for (i = 1; i <= m; ++i) cin >> b[i], ++sum[b[i]];
  sort(a + 1, a + n + 1);
  sort(b + 1, b + m + 1);
  a[0] = -1;
  a[n + 1] = l + 2;
  for (i = 1; i <= n; ++i)
    if (a[i] == a[i - 1] + 1)
      L[i] = L[i - 1];
    else
      L[i] = i;
  for (i = n; i >= 1; --i)
    if (a[i] == a[i + 1] - 1)
      R[i] = R[i + 1];
    else
      R[i] = i;
  for (i = 1; i <= 200000; ++i) sum[i] += sum[i - 1];
  for (i = 1; i <= n; ++i) {
    f[i] = ((f[i]) > (f[i - 1] + (L[i] == i) * (sum[a[i]] - sum[a[i] - 1]))
                ? (f[i])
                : (f[i - 1] + (L[i] == i) * (sum[a[i]] - sum[a[i] - 1])));
    g[i] = ((g[i]) > (f[i - 1] + (L[i] == i) * (sum[a[i]] - sum[a[i] - 1]))
                ? (g[i])
                : (f[i - 1] + (L[i] == i) * (sum[a[i]] - sum[a[i] - 1])));
    for (j = 1; b[j] <= a[i] && j <= m; ++j)
      if (i >= 1 + a[i] - b[j]) {
        g[i] =
            ((g[i]) > (f[L[i - (a[i] - b[j])] - 1] + sum[a[i]] - sum[b[j] - 1])
                 ? (g[i])
                 : (f[L[i - (a[i] - b[j])] - 1] + sum[a[i]] - sum[b[j] - 1]));
        f[i] =
            ((f[i]) > (f[L[i - (a[i] - b[j])] - 1] + sum[a[i]] - sum[b[j] - 1])
                 ? (f[i])
                 : (f[L[i - (a[i] - b[j])] - 1] + sum[a[i]] - sum[b[j] - 1]));
      }
    for (j = m; b[j] >= a[i] && j; --j)
      if (i + b[j] - a[i] <= n)
        f[R[i + b[j] - a[i]]] =
            ((f[R[i + b[j] - a[i]]]) > (g[i] + sum[b[j]] - sum[a[i]])
                 ? (f[R[i + b[j] - a[i]]])
                 : (g[i] + sum[b[j]] - sum[a[i]]));
  }
  cout << f[n] << '\n';
  return 0;
}
