#include <bits/stdc++.h>
using namespace std;
int n, m;
int L[100010], R[100010], pr[100010], nx[100010];
int a[100010], f[100010][2], ff[100010][2], b[100010];
inline int Read() {
  char c = getchar();
  int num = 0;
  while ('0' > c || c > '9') c = getchar();
  while ('0' <= c && c <= '9') num = num * 10 + c - '0', c = getchar();
  return (num);
}
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);
  for (int i = 1, j = 0; i <= m; pr[i] = j, i++)
    while (a[j + 1] <= b[i] && j < n) j++;
  for (int i = m, j = n + 1; i > 0; nx[i] = j, i--)
    while (a[j - 1] >= b[i] && j > 1) j--;
  R[n + 1] = n + 1, R[n] = n, L[1] = 1;
  for (int i = 2; i <= n; i++)
    if (a[i] == a[i - 1] + 1)
      L[i] = L[i - 1];
    else
      L[i] = i;
  for (int i = n - 1; i >= 1; i--)
    if (a[i] == a[i + 1] - 1)
      R[i] = R[i + 1];
    else
      R[i] = i;
  a[n + 1] = 1e9;
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) ff[j][0] = f[j][0], ff[j][1] = f[j][1];
    if (pr[i]) {
      for (int j = nx[i], k = i; j <= n; j++) {
        int p = a[pr[i]] + (j - pr[i]);
        while (b[k] <= p && k <= m) k++;
        int nm = max(ff[L[pr[i]] - 1][1], ff[R[pr[i]]][0]);
        f[R[j]][1] = max(f[R[j]][1], nm + k - i);
      }
    }
    for (int j = pr[i], k = i; j; j--) {
      int p = a[nx[i]] - (nx[i] - L[j]);
      while (b[k] >= p && k > 0) k--;
      int nm = ff[L[j] - 1][1] + i - k;
      f[R[nx[i]]][0] = max(f[R[nx[i]]][0], nm);
      f[R[nx[i]]][1] = max(f[R[nx[i]]][1], nm);
    }
    for (int j = 1; j <= n; j++)
      f[j][0] = max(f[j][0], f[j - 1][0]), f[j][1] = max(f[j][1], f[j - 1][1]);
  }
  printf("%d\n", max(f[n][0], f[n][1]));
}
