#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << "{";
  for (const T &a : v) out << a << ", ";
  out << "}";
  return out;
}
template <typename S, typename T>
ostream &operator<<(ostream &out, const pair<S, T> &p) {
  out << "(" << p.first << ", " << p.second << ")";
  return out;
}
const int INF = 1000000010;
const int dx[] = {0, 0, -1, 1};
const int dy[] = {-1, 1, 0, 0};
int n, m, res;
int M[100010];
int F[100010];
int L[100010];
int C[2010];
int A[100010];
int B[100010];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = (1); i < (n + 1); ++i) scanf("%d", &M[i]);
  sort(M + 1, M + n + 1);
  F[1] = 1;
  for (int i = (2); i < (n + 1); ++i)
    if (M[i - 1] + 1 == M[i])
      F[i] = F[i - 1];
    else
      F[i] = i;
  L[n] = n;
  for (int i = (n - 1); i > (0); --i)
    if (M[i + 1] - 1 == M[i])
      L[i] = L[i + 1];
    else
      L[i] = i;
  C[0] = -1;
  for (int i = (1); i < (m + 1); ++i) scanf("%d", &C[i]);
  sort(C + 1, C + m + 1);
  C[m + 1] = 1000000;
  m += 2;
  for (int i = (1); i < (n + 1); ++i) {
    int j = 0;
    while (j < m && C[j + 1] <= M[i]) ++j;
    A[i] = max(A[i], B[F[i] - 1]);
    for (int k = (j); k > (-1); --k)
      if (i - (M[i] - C[k]) >= 1)
        A[i] = max(A[i], j - k + 1 + B[F[i - (M[i] - C[k])] - 1]);
      else
        break;
    B[i] = max(B[i], A[i]);
    B[i] = max(B[i], B[i - 1]);
    for (int k = (j + 1); k < (m); ++k)
      if (i + C[k] - M[i] <= n)
        B[i + C[k] - M[i]] = max(B[L[i + C[k] - M[i]]], k - j + A[i]);
      else
        break;
    res = max(res, B[i]);
  }
  printf("%d\n", res);
  return 0;
}
