#include <bits/stdc++.h>
using namespace std;
const int MAXVAL = 300000;
const int MAXM = 5000;
int n, m;
int monster[MAXVAL];
int star[MAXVAL];
int hasMonster[MAXVAL];
int hasStar[MAXVAL];
int ans = 0;
int DP[MAXVAL];
int special[MAXVAL];
int monsterLeft[MAXVAL], monsterRight[MAXVAL];
int main() {
  scanf("%d%d", &n, &m);
  memset(hasMonster, 0, sizeof(hasMonster));
  memset(hasStar, 0, sizeof(hasStar));
  for (int i = 0; i < n; ++i) {
    scanf("%d", &monster[i]);
    hasMonster[monster[i]] = 1;
  }
  sort(monster, monster + n);
  memset(special, 0, sizeof(special));
  for (int i = 0; i < m; ++i) {
    scanf("%d", &star[i]);
    hasStar[star[i]] = 1;
  }
  sort(star, star + m);
  memset(special, 0, sizeof(special));
  for (int i = 0; i < MAXVAL; ++i) {
    if (hasMonster[i]) {
      if (hasStar[i]) {
        special[i] = 1;
      } else {
        int i1 = i + 1;
        while (i1 < MAXVAL && !hasMonster[i1] && !hasStar[i1]) {
          i1++;
        }
        if (i1 < MAXVAL && !hasMonster[i1]) {
          special[i] = 1;
        }
        int i2 = i - 1;
        while (i2 >= 0 && !hasMonster[i2] && !hasStar[i2]) {
          --i2;
        }
        if (i2 >= 0 && !hasMonster[i2]) {
          special[i] = 1;
        }
      }
    }
  }
  for (int i = 0; i < n;) {
    int i1 = i;
    while (i1 < n && monster[i1] == monster[i] + i1 - i) {
      i1++;
    }
    for (int j = i; j < i1; ++j) {
      monsterRight[j] = monster[i];
      monsterLeft[j] = monster[i1 - 1];
    }
    i = i1;
  }
  memset(DP, 0, sizeof(DP));
  int ans = 0;
  int monsterBelow = -1;
  int monsterAbove = 0;
  int starBelow = -1;
  int starAbove = 0;
  for (int i = 1; i < MAXVAL; ++i) {
    DP[i] = max(DP[i - 1], DP[i]);
    ans = max(ans, DP[i]);
    while (monsterBelow + 1 < n && monster[monsterBelow + 1] < i) {
      monsterBelow++;
    }
    while (monsterAbove < n && monster[monsterAbove] <= i) {
      monsterAbove++;
    }
    while (starBelow + 1 < m && star[starBelow + 1] < i) {
      starBelow++;
    }
    while (starAbove < m && star[starAbove] <= i) {
      starAbove++;
    }
    if (special[i]) {
      int extra = hasStar[i];
      int bes = DP[i - 1];
      for (int j = 0; j <= starBelow; ++j) {
        int needMonster = i - star[j];
        if (needMonster <= monsterBelow + 1) {
          int prev = monsterRight[monsterBelow - needMonster + 1] - 1;
          bes = max(bes, starBelow - j + 1 + DP[prev]);
        }
      }
      DP[i] = max(DP[i], bes + extra);
      for (int j = starAbove; j < m; ++j) {
        int needMonster = star[j] - i;
        if (monsterAbove + needMonster - 1 < n) {
          int next = monsterLeft[monsterAbove + needMonster - 1];
          DP[next] = max(DP[next], j - starAbove + 1 + bes + extra);
        }
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
