#include <bits/stdc++.h>
using namespace std;
void _fill_int(int* p, int val, int rep) {
  int i;
  for (i = 0; i < rep; i++) p[i] = val;
}
int N, M;
int A[100005], B[3000], st[100005], en[100005];
int dp[100005], S[300005];
void solve() {
  int f, i, j, k, l, x, y;
  cin >> N >> M;
  for (i = 0; i < N; i++) cin >> A[i];
  for (i = 0; i < M; i++) cin >> B[i], S[B[i]]++;
  sort(A, A + N);
  sort(B, B + M);
  for (i = 0; i < 200001; i++) S[i + 1] += S[i];
  en[N] = N;
  for (i = 1; i < N; i++) st[i] = (A[i - 1] + 1 == A[i]) ? st[i - 1] : i;
  for (i = N - 1; i >= 0; i--)
    en[i] = (A[i + 1] - 1 == A[i]) ? en[i + 1] : i + 1;
  for (i = 0; i < N; i++)
    if (st[i] == i) {
      int D = dp[i] + S[A[i]] - S[A[i] - 1];
      for (j = 0; j < M; j++)
        if (B[j] < A[i]) {
          x = i - (A[i] - B[j]);
          if (x >= 0) D = max(D, dp[st[x]] + S[A[i]] - S[B[j] - 1]);
        }
      dp[en[i]] = max(dp[en[i]], D);
      for (j = 0; j < M; j++)
        if (B[j] >= A[i]) {
          x = i + (B[j] - A[i]);
          if (x < N) dp[en[x]] = max(dp[en[x]], D + S[B[j]] - S[A[i]]);
        }
    }
  cout << dp[N] << endl;
}
int main(int argc, char** argv) {
  string s;
  if (argc == 1) ios::sync_with_stdio(false);
  for (int i = 1; i < argc; i++) s += argv[i], s += '\n';
  for (int i = s.size() - 1; i >= 0; i--) ungetc(s[i], stdin);
  solve();
  return 0;
}
