#include <bits/stdc++.h>
using namespace std;
int A[(1 << 18)];
int B[(1 << 18)];
int SA[(1 << 18)];
int SB[(1 << 18)];
int C[(1 << 18)];
int Pos[(1 << 18)];
int R[(1 << 18)];
int L[(1 << 18)];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  memset(A, 0, sizeof(A));
  memset(B, 0, sizeof(B));
  memset(C, 0, sizeof(C));
  memset(SA, 0, sizeof(SA));
  memset(SB, 0, sizeof(SB));
  int i, j;
  for (i = (0); i < (n); ++i) {
    int a;
    scanf("%d", &a);
    A[a] = 1;
  }
  for (i = (0); i < (m); ++i) {
    int a;
    scanf("%d", &a);
    B[a] = 1;
  }
  for (i = (1); i < ((1 << 18)); ++i) {
    SA[i] = SA[i - 1] + A[i - 1];
    SB[i] = SB[i - 1] + B[i - 1];
  }
  for (i = (0); i < ((1 << 18)); ++i)
    if (B[i] != 0) {
      int pos = i;
      if (A[i] == 0) {
        while (pos != (1 << 18) && A[pos] == 0) ++pos;
        if (pos != (1 << 18)) C[pos] = 1;
        pos = i;
        while (pos != 0 && A[pos] == 0) --pos;
        if (pos != 0) {
          while (A[pos] != 0) --pos;
          C[pos + 1] = 1;
        }
      } else {
        while (A[pos] != 0) --pos;
        C[pos + 1] = 1;
      }
    }
  int cnt = 0;
  for (i = (0); i < ((1 << 18)); ++i)
    if (C[i] == 1) {
      Pos[cnt] = i;
      ++cnt;
    }
  memset(R, 0, sizeof(R));
  memset(L, 0, sizeof(L));
  int pos = 0;
  for (i = (0); i < ((1 << 18)); ++i) {
    while (pos != cnt && Pos[pos] < i) ++pos;
    if (i == 0 || (A[i] == 0 && A[i - 1] != 0)) {
      for (j = (pos); j < (cnt); ++j) {
        int a = Pos[j];
        int aCnt = SA[a] - SA[i];
        int bCnt = SB[a] - SB[a - aCnt];
        L[a] = max(L[a], R[i] + bCnt);
      }
    }
    if (C[i] != 0) {
      int aCnt = i;
      int bCnt = 0;
      for (j = (i); j < ((1 << 18) - 1); ++j)
        if (A[j] != 0) {
          if (B[aCnt]) ++bCnt;
          ++aCnt;
          R[j + 1] = max(R[j + 1], L[i] + bCnt);
        }
    }
  }
  int res = 0;
  for (i = (0); i < ((1 << 18)); ++i) res = max(res, R[i]);
  printf("%d\n", res);
  return 0;
};
