#include <bits/stdc++.h>
using namespace std;
int n, m;
int mon[100005], sp[2005];
void init() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &mon[i]);
  for (int i = 0; i < m; i++) scanf("%d", &sp[i]);
  sort(mon + 1, mon + n + 1);
  sort(sp, sp + m);
}
int prv[100005], nxt[100005];
int dp[100005], dp2[100005];
void process() {
  memset(dp, 0, sizeof dp);
  memset(dp2, 0, sizeof dp2);
  prv[1] = 0, nxt[n] = n;
  for (int i = 2; i <= n; i++)
    if (mon[i - 1] + 1 == mon[i])
      prv[i] = prv[i - 1];
    else
      prv[i] = i - 1;
  for (int i = n - 1; i > 0; i--)
    if (mon[i] + 1 == mon[i + 1])
      nxt[i] = nxt[i + 1];
    else
      nxt[i] = i;
  for (int i = 1; i <= n; i++) {
    int md = lower_bound(sp, sp + m, mon[i]) - sp;
    dp2[i] = dp[i - 1];
    for (int j = 0; j < md; j++) {
      int tmp = i - (mon[i] - sp[j]);
      if (tmp > 0) dp2[i] = max(dp2[i], dp[prv[tmp]] + md - j);
    }
    dp[i] = max(dp[i], dp2[i]);
    for (int j = md; j < m; j++) {
      int tmp = i + (sp[j] - mon[i]);
      if (tmp <= n) dp[nxt[tmp]] = max(dp[nxt[tmp]], dp2[i] + j - md + 1);
    }
  }
  printf("%d\n", dp[n]);
}
int main() {
  init();
  process();
  return 0;
}
