#include <bits/stdc++.h>
using namespace std;
const int Maxn = 100010;
const int Maxm = 2010;
const int inf = 2147483647;
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
  return x * f;
}
int n, m, a[Maxn], b[Maxm], f[Maxn], g[Maxn], mark[200010];
int L[Maxn], R[Maxn];
int main() {
  n = read(), m = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  a[n + 1] = inf;
  a[0] = -inf;
  for (int i = 1; i <= m; i++) mark[b[i] = read()] = 1;
  sort(a + 1, a + 1 + n);
  sort(b + 1, b + 1 + m);
  L[1] = 1;
  for (int i = 2; i <= n; i++)
    L[i] = ((a[i] == a[i - 1] + 1) ? L[i - 1] + 1 : 1);
  R[n] = 1;
  for (int i = n - 1; i; i--)
    R[i] = ((a[i] + 1 == a[i + 1]) ? R[i + 1] + 1 : 1);
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    g[i] = max(mark[a[i]] + f[i - 1], g[i - 1]);
    f[i] = max(f[i], f[i - 1]);
    int c = mark[a[i]];
    for (int j = m; j; j--)
      if (b[j] < a[i]) {
        if (a[i] - b[j] > i - 1) break;
        c++;
        g[i] = max(g[i], f[i - (a[i] - b[j]) - L[i - (a[i] - b[j])]] + c);
      }
    c = 0;
    for (int j = 1; j <= m; j++)
      if (b[j] > a[i]) {
        if (b[j] - a[i] > n - i) break;
        c++;
        f[i + b[j] - a[i] + R[i + b[j] - a[i]] - 1] =
            max(f[i + b[j] - a[i] + R[i + b[j] - a[i]] - 1], g[i] + c);
      }
    f[i] = max(f[i], g[i]);
    ans = max(ans, f[i]);
  }
  printf("%d", ans);
}
