#include <bits/stdc++.h>
using namespace std;
int monster[100010];
int star[2010];
int dp[100010];
int rdp[100010];
int pre[100010];
int next[100010];
int main() {
  int fix, index, i, j, n, m;
  cin >> n >> m;
  memset(dp, 0, sizeof(dp));
  memset(rdp, 0, sizeof(rdp));
  monster[0] = -(1 << 29);
  monster[n + 1] = (1 << 29);
  for (i = 1; i <= n; i++) {
    cin >> monster[i];
  }
  for (i = 1; i <= m; i++) {
    cin >> star[i];
  }
  sort(monster + 1, monster + n + 1);
  sort(star + 1, star + m + 1);
  for (i = 1; i <= n; i++) {
    if (monster[i] == monster[i - 1] + 1) {
      pre[i] = pre[i - 1];
    } else {
      pre[i] = i;
    }
  }
  for (i = 1, index = 0; i <= n; i++) {
    dp[i] = max(dp[i], dp[i - 1]);
    rdp[i] = max(rdp[i - 1], dp[pre[i] - 1]);
    while (index < m && star[index + 1] <= monster[i]) {
      index++;
    }
    for (j = index; j && monster[i] - star[j] < i; j--) {
      int cost = monster[i] - star[j];
      dp[i] = max(dp[i], dp[pre[i - cost] - 1] + (index - j + 1));
      rdp[i] = max(rdp[i], dp[pre[i - cost] - 1] + (index - j + 1));
    }
    for (j = index + 1; j <= m && star[j] - monster[i] <= n - i; j++) {
      int cost = star[j] - monster[i];
      dp[i + cost] = max(dp[i + cost], rdp[i] + (j - index));
    }
  }
  cout << dp[n] << endl;
}
