#include <bits/stdc++.h>
using namespace std;
inline int Get() {
  int res = 0, q = 1;
  char ch = getchar();
  while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
  if (ch == '-') q = -1, ch = getchar();
  while (ch >= '0' && ch <= '9') res = res * 10 + ch - '0', ch = getchar();
  return res * q;
}
const double eps = 1e-12, pi = M_PI;
const int oo = (int)2e9, mod = (int)1e9 + 7;
const long long INF = (long long)1e17;
const int N = (int)1e5;
typedef int arr[N + 10];
arr f, g, a, b, num;
int i, j, k, p, n, m, mx;
int main() {
  scanf(
      "%d"
      "%d"
      "\n",
      &n, &m);
  for (int i = (0), end = (n - 1); i <= end; ++i) scanf("%d", a + i);
  for (int i = (0), end = (m - 1); i <= end; ++i) scanf("%d", b + i);
  sort(a, a + n), sort(b, b + m);
  for (int i = (0), end = (n - 1); i <= end; ++i) {
    if (a[i] == a[i - 1] + 1 && i)
      num[i] = num[i - 1];
    else
      num[i] = i;
    for (; b[mx] <= a[i] && mx < m; ++mx)
      ;
    g[i + 1] = f[num[i]];
    for (int j = mx - 1; j >= 0 && i - a[i] + b[j] >= 0; --j)
      g[i + 1] = ((g[i + 1]) > (f[num[i - (a[i] - b[j])]] + mx - j)
                      ? (g[i + 1])
                      : (f[num[i - (a[i] - b[j])]] + mx - j));
    f[i + 1] = ((f[i + 1]) > (g[i + 1]) ? (f[i + 1]) : (g[i + 1]));
    for (int j = mx; j < m && i + b[j] - a[i] + 1 <= n; ++j)
      f[i + b[j] - a[i] + 1] =
          ((f[i + b[j] - a[i] + 1]) > (g[i + 1] + j - mx + 1)
               ? (f[i + b[j] - a[i] + 1])
               : (g[i + 1] + j - mx + 1));
    f[i + 1] = ((f[i + 1]) > (f[i]) ? (f[i + 1]) : (f[i]));
  }
  printf(
      "%d"
      "\n",
      f[n]);
  return 0;
}
