#include <bits/stdc++.h>
#pragma comment(linker, "/stack:16777216")
using namespace std;
const int INF = 1000000000;
const int MAX = 400007;
const int MAX2 = 4007;
const int BASE = 1000000000;
int n, m, q, w;
int A[MAX];
int B[MAX2];
int S[MAX];
int E[MAX];
int R[2][MAX2][2];
pair<int, int> Q[MAX];
bool W[MAX];
int I[MAX2];
int F(int i, int j) {
  int d = 0;
  if (i < I[j])
    d = (Q[I[j]].second - Q[i].first + 1) - (E[I[j]] - (i == 0 ? 0 : E[i - 1]));
  else if (i > I[j])
    d = -((Q[i].second - Q[I[j]].first + 1) -
          (E[i] - (I[j] == 0 ? 0 : E[I[j] - 1])));
  return S[Q[i].second + d] - S[Q[i].first + d - 1];
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = (0); i < (n); ++i) scanf("%d", &A[i]);
  for (int i = (0); i < (m); ++i) scanf("%d", &B[i]);
  sort(A, A + n);
  sort(B, B + m);
  int i = 0;
  while (i < n) {
    int j = 1;
    while (i + j < n && A[i + j] == A[i] + j) ++j;
    Q[q++] = make_pair(A[i], A[i] + j - 1);
    i += j;
  }
  for (int i = (0); i < (m); ++i) {
    int x = B[i];
    int pos = upper_bound(Q, Q + q, make_pair(x, INF)) - Q - 1;
    if (pos != -1) W[pos] = 1;
    if (pos + 1 < q) W[pos + 1] = 1;
  }
  for (int i = (0); i < (m); ++i) S[B[i]] = 1;
  for (int i = (1); i < (MAX); ++i) S[i] = S[i - 1] + S[i];
  E[0] = Q[0].second - Q[0].first + 1;
  for (int i = (1); i < (q); ++i)
    E[i] = E[i - 1] + Q[i].second - Q[i].first + 1;
  w = 0;
  for (int i = (0); i < (q); ++i)
    if (W[i] == 1) I[w++] = i;
  int cur = 0, next = 1;
  int res = 0;
  for (int i = (0); i < (w); ++i) R[cur][i][0] = R[cur][i][1] = -INF;
  R[cur][0][0] = 0;
  for (int i = (0); i < (q); ++i) {
    for (int j = (0); j < (w); ++j) R[next][j][0] = R[next][j][1] = -INF;
    for (int j = (0); j < (w); ++j) {
      R[cur][j + 1][0] = max(R[cur][j + 1][0], R[cur][j][0]);
      if (I[j] >= i) R[cur][j][1] = max(R[cur][j][1], R[cur][j][0] + F(i, j));
      if (i + 1 < q)
        R[next][j][1] = max(R[next][j][1], R[cur][j][1] + F(i + 1, j));
      if (I[j] <= i) R[next][j + 1][0] = max(R[next][j + 1][0], R[cur][j][1]);
      res = max(res, max(R[cur][j][0], R[cur][j][1]));
    }
    swap(cur, next);
  }
  printf("%d\n", res);
  return 0;
}
