#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5, maxm = 2005, maxp = 2e5 + 5;
int n, m, a[maxn + 1], b[maxm + 1];
void read() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  for (int i = 1; i <= m; i++) scanf("%d", b + i);
  sort(a + 1, a + 1 + n);
  sort(b + 1, b + 1 + m);
}
int d[maxn + 1], s[maxp + 1], z[maxn + 1], t[maxn + 1];
void work() {
  int tt = 0, top = 0;
  for (int i = 1; i <= m; i++) {
    for (int j = i == 1 ? 1 : b[i - 1]; j <= b[i] - 1; j++) {
      s[j] = tt;
    }
    tt++;
  }
  for (int i = n; i > 0; i--) {
    if (i == n || a[i + 1] - 1 != a[i]) {
      top = i;
    }
    t[i] = top;
  }
  for (int j = b[m]; j <= maxp; j++) s[j] = tt;
  for (int i = 1; i <= n; i++) {
    z[i] = max(z[i - 1], z[i]);
    d[i] = max(d[i], d[i - 1]);
    d[i] = max(d[i], z[i - 1]);
    if (t[i] != i) continue;
    for (int j = 1; j <= m; j++) {
      if (b[j] <= a[i]) {
        int num = a[i] - b[j] + 1;
        if (num <= i) {
          d[i] = max(d[i], s[a[i]] - s[b[j] - 1] + z[i - num]);
        }
      }
      if (b[j] >= a[i]) {
        int num = b[j] - a[i];
        if (i + num > n) break;
        z[t[i + num]] = max(z[t[i + num]], d[i] + s[b[j]] - s[a[i]]);
      }
      z[i] = max(z[i], d[i]);
    }
  }
  printf("%d\n", z[n]);
}
int main() {
  read();
  work();
  return 0;
}
