#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
const int MAXM = 2005;
int g[MAXN], f[MAXN];
int n, m, monster[MAXN], star[MAXM], start[MAXN];
void upd(int &x, int y) {
  if (y > x) x = y;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", &monster[i]);
  }
  for (int i = 0; i < m; i++) {
    scanf("%d", &star[i]);
  }
  sort(monster, monster + n);
  sort(star, star + m);
  for (int i = 0; i < n; i++) {
    if (!i || monster[i] != monster[i - 1] + 1) {
      start[i] = i;
    } else {
      start[i] = start[i - 1];
    }
  }
  memset(g, 0, sizeof g);
  memset(f, 0, sizeof f);
  for (int i = 0; i < n; i++) {
    int nxtstar = upper_bound(star, star + m, monster[i]) - star;
    if (start[i] > 0) upd(g[i], f[start[i] - 1]);
    for (int leftstar = nxtstar - 1; leftstar >= 0; leftstar--) {
      int leftmonster = i - (monster[i] - star[leftstar]);
      if (leftmonster < 0) break;
      leftmonster = start[leftmonster] - 1;
      upd(g[i], (leftmonster >= 0 ? f[leftmonster] : 0) + nxtstar - leftstar);
    }
    for (int rightstar = nxtstar; rightstar < m; rightstar++) {
      int rightmonster = i + (star[rightstar] - monster[i]);
      if (rightmonster >= n) break;
      upd(f[rightmonster], g[i] + rightstar - nxtstar + 1);
    }
    if (i > 0) upd(f[i], f[i - 1]);
    upd(f[i], g[i]);
  }
  printf("%d\n", f[n - 1]);
  return 0;
}
