#include <bits/stdc++.h>
using namespace std;
long long M = 1e9 + 7;
const int N = 2e5 + 7;
int n, m;
int a[N], b[N];
int l[N], r[N];
int z[N], d[N];
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= m; i++) {
    cin >> b[i];
  }
  sort(a + 1, a + n + 1);
  sort(b + 1, b + m + 1);
  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;
  r[n] = n;
  for (int i = n - 1; i >= 1; i--)
    if (a[i] == a[i + 1] - 1)
      r[i] = r[i + 1];
    else
      r[i] = i;
  int pnt = 0;
  for (int i = 1; i <= n; i++) {
    while (pnt < m && b[pnt + 1] <= a[i]) pnt++;
    for (int j = 1; j <= pnt; j++) {
      int k = i - (a[i] - b[j]);
      if (k <= 0) continue;
      k = l[k];
      d[i] = max(d[i], z[k - 1] + pnt - j + 1);
    }
    z[i] = max({z[i], d[i], z[i - 1]});
    z[i + 1] = max(z[i + 1], d[i]);
    d[i] = max(d[i], z[i - 1]);
    for (int j = pnt + 1; j <= m; j++) {
      int k = i + (b[j] - a[i]);
      if (k > n) continue;
      k = r[k];
      z[k] = max(z[k], d[i] + j - pnt);
    }
  }
  cout << z[n];
}
