#include <bits/stdc++.h>
using namespace std;
template <class T>
void debug(T a, T b) {
  ;
}
template <class T>
void chmin(T& a, const T& b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T& a, const T& b) {
  if (a < b) a = b;
}
namespace std {
template <class S, class T>
ostream& operator<<(ostream& out, const pair<S, T>& a) {
  out << '(' << a.first << ',' << a.second << ')';
  return out;
}
}  // namespace std
const int INF = 5e8;
int n, m;
int dp1[2][2005], dp2[2][2005];
int pud[100005], ispud[200005], pudsum[200005];
int mark[200005], marksum[200005];
int con[200005];
int MX = 200003;
int main() {
  cin >> n >> m;
  int st = MX;
  for (int i = 0; i < (n); ++i) {
    int a;
    scanf("%d", &a);
    ispud[a] = 1;
    pud[i] = a;
    chmin(st, a);
  }
  sort(pud, pud + n);
  for (int i = 0; i < (m); ++i) {
    int a;
    scanf("%d", &a);
    mark[a] = 1;
  }
  for (int i = 0; i < (MX); ++i) {
    pudsum[i + 1] = pudsum[i] + ispud[i];
    marksum[i + 1] = mark[i] + marksum[i];
  }
  for (int i = 0; i < (MX); ++i)
    if (ispud[i] && ispud[i + 1]) con[i] = 1;
  for (int k = 0; k < (2); ++k)
    for (int j = 0; j < (2005); ++j) dp1[k][j] = dp2[k][j] = INF;
  int cur = 0, nxt = 1;
  dp1[cur][0] = 0;
  int ans = 0;
  for (int i = st; i < MX; ++i) {
    for (int j = 0; j < (m + 1); ++j)
      if (dp1[cur][j] <= n) {
        chmax(ans, j);
        chmin(dp1[nxt][j], dp1[cur][j]);
        if (ispud[i]) {
          int sum = pudsum[i + 1] - dp1[cur][j];
          if (sum <= 0) continue;
          int nmark = marksum[i + 1] - marksum[i + 1 - sum];
          chmin(dp2[cur][j + nmark], pudsum[i + 1]);
        }
      }
    for (int j = 0; j < (m + 1); ++j)
      if (dp2[cur][j] <= n) {
        chmax(ans, j);
        chmin(dp2[nxt][j + mark[i + 1]], dp2[cur][j] + 1);
        if (!con[pud[dp2[cur][j] - 1]]) chmin(dp1[nxt][j], dp2[cur][j]);
      }
    swap(cur, nxt);
    for (int j = 0; j < (m + 1); ++j) dp1[nxt][j] = dp2[nxt][j] = INF;
  }
  cout << ans << endl;
  return 0;
}
