#include <bits/stdc++.h>
using namespace std;
int i, j, k, m, n;
int mst[101000], cell[101000], l[101000], r[101000];
int bit[101000 * 2];
int lowbit(int x) { return x & (-x); }
void insert(int x) {
  while (x < 101000 * 2) {
    bit[x]++;
    x += lowbit(x);
  }
}
int sum(int x) {
  int ret = 0;
  while (x) {
    ret += bit[x];
    x -= lowbit(x);
  }
  return ret;
}
int getsum(int l, int r) { return sum(r) - sum(l - 1); }
void init() {
  cin >> n >> m;
  for (i = 1; i <= n; i++) scanf("%d", &mst[i]);
  for (i = 1; i <= m; i++) {
    scanf("%d", &cell[i]);
    insert(cell[i]);
  }
  sort(mst + 1, mst + n + 1);
  sort(cell + 1, cell + m + 1);
  l[1] = 1;
  for (i = 2; i <= n; i++) l[i] = (mst[i] == mst[i - 1] + 1) ? l[i - 1] : i;
  r[n] = n;
  for (i = n - 1; i >= 1; i--) r[i] = (mst[i] == mst[i + 1] - 1) ? r[i + 1] : i;
}
int f[101000], g[101000];
void dp() {
  int num, pos;
  memset(f, 0, sizeof(f));
  memset(g, 0, sizeof(g));
  for (i = 1; i <= n; i++) {
    int note = getsum(mst[i], mst[i]);
    g[i] = f[i - 1] + note;
    for (j = 1; j <= m && cell[j] <= mst[i]; j++) {
      num = mst[i] - cell[j] + 1;
      if (i - num + 1 <= 0) continue;
      pos = l[i - num + 1];
      g[i] = max(g[i], f[pos - 1] + getsum(mst[i] - i + pos, mst[i]));
    }
    f[i] = max(f[i], g[i]);
    for (; j <= m; j++) {
      num = cell[j] - mst[i] + 1;
      if (n - i + 1 < num) break;
      pos = r[i + num - 1];
      f[pos] = max(f[pos], g[i] + getsum(mst[i] + 1, mst[i] + pos - i));
    }
  }
}
int main() {
  init();
  dp();
  cout << f[n] << endl;
  return 0;
}
