#include <bits/stdc++.h>
using namespace std;
const int INF = 1E9 + 7;
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);
}
int n, m;
vector<pair<int, int> > mon;
vector<int> spec;
int sum[100005 * 2];
int best[100005 * 2];
int get_sum(int l, int r) {
  if (l < 0) l = 0;
  if (l > r) return 0;
  return sum[r] - (l > 0 ? sum[l - 1] : 0);
}
int trzebaL[2005];
int trzebaR[2005];
void normuj(int idx) {
  for (int i = (0); i <= (m - 1); ++i) {
    while (trzebaL[i] <= idx) {
      if (mon[idx].first - get_sum(idx - trzebaL[i], idx - 1) <= spec[i])
        break;
      else
        trzebaL[i]++;
    }
    while (trzebaR[i] > 0) {
      int cand = trzebaR[i] - 1;
      int il = get_sum(idx + 1, idx + cand) + mon[idx].second;
      if (mon[idx].first + il - 1 >= spec[i]) {
        trzebaR[i]--;
      } else
        break;
    }
  }
}
int get_best(int r) { return best[r]; }
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  vector<int> pos;
  for (int i = (1); i <= (n); ++i) {
    int x;
    cin >> x;
    pos.push_back(x);
  }
  for (int i = (1); i <= (m); ++i) {
    int x;
    cin >> x;
    spec.push_back(x);
  }
  sort((pos).begin(), (pos).end());
  sort((spec).begin(), (spec).end());
  {
    if (0) {
      cerr << "spec"
           << " = ";
      for (__typeof(((spec)).begin()) it = (((spec)).begin());
           it != ((spec)).end(); ++it)
        cerr << *it << ", ";
      cout << endl;
    }
  };
  int act = 0, last = -10, ile = 0;
  {
    if (0) {
      cerr << "pos"
           << " = ";
      for (__typeof(((pos)).begin()) it = (((pos)).begin());
           it != ((pos)).end(); ++it)
        cerr << *it << ", ";
      cout << endl;
    }
  };
  while (act < n) {
    if (pos[act] == last + 1)
      ++ile, last = pos[act];
    else {
      if (ile) mon.push_back(make_pair(last - ile + 1, ile));
      last = pos[act];
      ile = 1;
    }
    ++act;
  }
  if (ile) mon.push_back(make_pair(last - ile + 1, ile));
  int s = 0;
  n = ((int)(mon).size());
  for (int i = (0); i <= (n - 1); ++i) s += mon[i].second, sum[i] = s;
  for (int j = (n); j <= (2 * n + 2); ++j) sum[j] = s;
  for (int i = (0); i <= (m - 1); ++i) trzebaL[i] = 0, trzebaR[i] = n + 1;
  if (0)
    for (__typeof((mon).begin()) it = ((mon).begin()); it != (mon).end(); ++it)
      cout << it->first << " " << it->second << endl;
  int last_mniejszy = -1;
  for (int i = (0); i <= (n - 1); ++i) {
    normuj(i);
    if (0) {
      cout << "TTT " << i << endl;
      {
        if (0)
          cerr << "mon[i].FI"
               << " = " << mon[i].first << endl;
      };
      for (int j = (0); j <= (m - 1); ++j)
        cout << j << " " << trzebaL[j] << " " << trzebaR[j] << endl;
    }
    while (last_mniejszy + 1 < m) {
      if (spec[last_mniejszy + 1] < mon[i].first)
        ++last_mniejszy;
      else
        break;
    }
    int bestLewe = 0;
    for (int j = (0); j <= (last_mniejszy); ++j) {
      if (trzebaL[j] <= i) {
        int ilep = last_mniejszy - j + 1;
        int b = get_best(i - trzebaL[j] - 1);
        bestLewe = max(bestLewe, ilep + b);
      }
    }
    bestLewe = max(bestLewe, get_best(i - 1));
    {
      if (0)
        cerr << "last_mniejszy"
             << " = " << last_mniejszy << endl;
    };
    for (int j = (last_mniejszy + 1); j <= (m - 1); ++j) {
      int k = trzebaR[j];
      if (i + k < n) {
        int b = bestLewe + j - last_mniejszy;
        best[i + k] = max(best[i + k], b);
      }
    }
    best[i] = max(best[i], bestLewe);
    if (0) cout << "_______________" << endl;
    if (i) best[i] = max(best[i], best[i - 1]);
  }
  if (0)
    for (int i = (0); i <= (n - 1); ++i)
      cout << "F " << i << " " << best[i] << endl;
  int b = 0;
  for (int i = (0); i <= (n - 1); ++i) b = max(b, best[i]);
  cout << b << endl;
  return 0;
}
