#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const int inf = 1e9;
int ans, n, m, pre[N], a[N], b[N], z[N], d[N], l[N], r[N];
int get(int l, int r) { return pre[r] - pre[l - 1]; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= m; i++) {
    cin >> b[i];
    pre[b[i]]++;
  }
  for (int i = 1; i < N; i++) pre[i] += pre[i - 1];
  sort(a + 1, a + n + 1);
  sort(b + 1, b + m + 1);
  a[0] = a[n + 1] = inf;
  for (int i = 1; i <= n; i++) {
    l[i] = i;
    if (a[i - 1] + 1 == a[i]) l[i] = l[i - 1];
  }
  for (int i = n; i >= 1; i--) {
    r[i] = i;
    if (a[i + 1] == a[i] + 1) r[i] = r[i + 1];
  }
  for (int i = 1; i <= n; i++) {
    d[i] = d[i - 1];
    d[i] = max(d[i], d[i - 1]);
    z[i] = max(z[i], d[i - 1]);
    if (l[i] == i) d[i] = max(d[i], z[i]);
    for (int j = 1; j <= m; j++)
      if (b[j] <= a[i] && i - (a[i] - b[j]) > 0)
        d[i] = max(d[i], z[l[i - (a[i] - b[j])]] + get(b[j], a[i]));
    for (int j = 1; j <= m; j++)
      if (b[j] >= a[i] && i + (b[j] - a[i]) <= n)
        z[r[i + (b[j] - a[i])] + 1] =
            max(z[r[i + (b[j] - a[i])] + 1], d[i] + get(a[i] + 1, b[j]));
    ans = max(ans, z[i]);
  }
  ans = max(ans, z[n + 1]);
  cout << ans << "\n";
}
