#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int f = 1, x = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline void write(int x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
inline void print(int x) {
  write(x);
  printf(" ");
}
int n, m;
int f[100005][2];
int a[100005], b[2005];
int pre[100005], nxt[100005];
int fir[100005], ed[100005];
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  for (int i = 1; i <= m; i++) b[i] = read();
  sort(a + 1, a + 1 + n);
  sort(b + 1, b + 1 + m);
  fir[1] = 1;
  for (int i = 2; i <= n; i++) {
    if (a[i] != a[i - 1] + 1)
      fir[i] = i;
    else
      fir[i] = fir[i - 1];
  }
  for (int i = n; i >= 1; i--) {
    if (a[i] != a[i + 1] - 1)
      ed[i] = i;
    else
      ed[i] = ed[i + 1];
  }
  for (int i = 1, j = 0; i <= n; i++) {
    while (b[j + 1] < a[i] && j < m) j++;
    pre[i] = j;
  }
  for (int i = n, j = m + 1; i >= 1; i--) {
    while (b[j - 1] > a[i] && j > 1) j--;
    nxt[i] = j;
  }
  for (int i = 1; i <= n; i++) {
    if (fir[i] == fir[i - 1] && ed[i] == ed[i + 1]) continue;
    f[i][0] = max(f[i][0], max(f[fir[i] - 1][0], f[fir[i] - 1][1]));
    for (int j = 1; j <= m; j++) {
      int pa = pre[i] - j + 1;
      if (pa <= 0) break;
      int pos = a[i] - b[pa];
      if (pos > i) break;
      int gg = fir[i - pos];
      if (gg <= 0) break;
      f[i][0] = max(f[i][0], max(f[gg - 1][0], f[gg - 1][1]) + j);
    }
    if (b[nxt[i] - 1] == a[i]) f[i][0]++;
    for (int j = 1; j <= m; j++) {
      int pa = nxt[i] + j - 1;
      if (pa > m) break;
      int pos = b[pa] - a[i];
      if (pos > n - i) break;
      int gg = ed[i + pos];
      if (gg > n) break;
      f[gg][1] = max(f[gg][1], f[i][0] + j);
      if (a[gg] - a[i] + 1 == j) f[gg][0] = max(f[gg][0], f[i][0] + j);
    }
  }
  printf("%d\n", max(f[n][0], f[n][1]));
  return 0;
}
