#include <bits/stdc++.h>
using namespace std;
const long long linf = 1e18 + 5;
const int mod = (int)1e9 + 7;
const int logN = 17;
const int inf = 1e9;
const int N = 2e5 + 5;
int l[N], r[N], n, m, a[N], b[N], dp[N], dp2[N], pre[N];
int take(int x, int y) { return pre[y] - pre[x - 1]; }
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d", &b[i]);
    pre[b[i]]++;
  }
  for (int i = 1; i <= N - 1; i++) pre[i] += pre[i - 1];
  sort(a + 1, a + n + 1);
  sort(b + 1, b + m + 1);
  a[0] = -1;
  a[n + 1] = -1;
  for (int i = 1; i <= n; i++) {
    l[i] = i;
    if (a[i] - 1 == a[i - 1]) 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++) {
    dp[i] = dp[i - 1];
    dp2[i] = max(dp2[i], dp[i - 1]);
    dp2[i] = max(dp2[i], dp2[i - 1]);
    for (int j = 1; j <= m; j++) {
      if (b[j] <= a[i] && i - a[i] + b[j] > 0) {
        int t = l[i - a[i] + b[j]];
        dp[i] = max(dp[i], dp2[t] + take(b[j], a[i]));
      }
    }
    if (l[i] == i) dp[i] = max(dp[i], dp2[i]);
    for (int j = 1; j <= m; j++)
      if (b[j] >= a[i] && i + b[j] - a[i] <= n) {
        int t = i + (b[j] - a[i]) + 1;
        dp2[t] = max(dp2[t], dp[i] + take(a[i] + 1, b[j]));
      }
  }
  cout << *max_element(dp2 + 1, dp2 + n + 2) << '\n';
  return 0;
}
