#include <bits/stdc++.h>
using namespace std;
template <class C>
void mini(C& a4, C b4) {
  a4 = min(a4, b4);
}
template <class C>
void maxi(C& a4, C b4) {
  a4 = max(a4, b4);
}
template <class T1, class T2>
ostream& operator<<(ostream& rout, pair<T1, T2> pair) {
  return rout << "(" << pair.first << ", " << pair.second << ")";
}
const int MX = 2e5 + 10;
bool b[MX];
bool s[MX];
vector<int> st;
int main() {
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int n, m;
  cin >> n >> m;
  int M = 0;
  vector<int> T(n), S(n);
  for (int i = 0; i < (n); ++i) {
    int j;
    cin >> j;
    b[j - 1] = true;
    maxi(M, j);
  }
  for (int i = 0; i < (m); ++i) {
    int j;
    cin >> j;
    s[j - 1] = true;
    st.push_back(j - 1);
  }
  sort((st).begin(), (st).end());
  int no = 0;
  int cnt = 0;
  for (int i = 0; i < (M); ++i) {
    if (b[i]) {
      int val = 0;
      int j = 0;
      while (j < m && st[j] < i) {
        int p = st[j];
        int ile = i - p;
        if (ile <= no) maxi(val, cnt - j + S[no - ile]);
        ++j;
      }
      maxi(val, S[no]);
      if (j < m && st[j] == i) {
        ++val;
        ++j;
        ++cnt;
      }
      maxi(T[no], val);
      while (j < m) {
        int p = st[j];
        int ile = p - i;
        if (no + ile < n) maxi(T[no + ile], val + 1 + j - cnt);
        ++j;
      }
      if (no) {
        maxi(T[no], T[no - 1]);
        maxi(S[no], S[no - 1]);
      }
      if (!b[i + 1]) maxi(S[no + 1], T[no]);
      ++no;
    } else if (s[i])
      ++cnt;
  }
  cout << T[n - 1] << endl;
  return 0;
}
