#include <bits/stdc++.h>
#pragma GCC optimize(10000)
using namespace std;
int a[500007], b[500007], pre[500007], co[500007], l[500007], dp1[500007],
    dp2[500007], f[500007];
inline int read() {
  int x = 0;
  char ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) {
    x = x * 10 + ch - 48;
    ch = getchar();
  }
  return x;
}
int main() {
  int n = read(), m = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  sort(a + 1, a + 1 + n);
  for (int i = 1; i <= m; i++) {
    b[i] = read();
    pre[b[i]]++;
  }
  for (int i = 1; i <= 200000; i++) {
    pre[i] += pre[i - 1];
  }
  int x = 0;
  for (int i = 1; i <= n; i++) {
    co[a[i]] = i;
  }
  for (int i = 1; i <= 200000; i++)
    if (!co[i]) co[i] = co[i - 1];
  l[1] = 1;
  for (int i = 2; i <= n; i++) {
    if (a[i - 1] + 1 == a[i])
      l[i] = l[i - 1];
    else
      l[i] = i;
  }
  for (int i = 1; i <= n; i++) {
    dp1[i] = max(dp1[i - 1], dp2[i - 1]) + pre[a[i]] - pre[a[i] - 1];
    for (int j = 1; j <= m; j++) {
      if (a[i] - b[j] > 0 && i - (a[i] - b[j]) > 0) {
        int t = l[i - (a[i] - b[j])];
        dp1[i] = max(dp1[i], max(dp1[t - 1], dp2[t - 1]) + pre[a[i]] -
                                 pre[a[i] - i + t - 1]);
      }
      int m = co[b[j]];
      if (m > 0 && a[i] + 1 != a[i + 1] && m < i)
        dp2[i] = max(dp2[i], dp1[m] - (pre[a[m]] - pre[a[m] + i - m]));
    }
  }
  cout << max(dp1[n], dp2[n]) << endl;
  return 0;
}
