#include <bits/stdc++.h>
using namespace std;
inline bool setmin(int &x, int y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(int &x, int y) { return (y > x) ? x = y, 1 : 0; }
inline bool setmin(long long &x, long long y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(long long &x, long long y) { return (y > x) ? x = y, 1 : 0; }
const int N = 100000;
const int inf = (int)1e9 + 1;
const long long big = (long long)1e18 + 1;
const int P = 239;
const int P1 = 31;
const int P2 = 57;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const int MOD2 = 998244353;
const long double eps = 1e-9;
const double pi = atan2(0, -1);
const int ABC = 26;
int a[100000], b[2000];
int last[100000];
int pref[200000 + 1];
int first_pos[2000];
int dp[100000][2];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.precision(20);
  cout << fixed;
  int n, m;
  cin >> n >> m;
  for (int i = (0); i < (n); i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  last[0] = 0;
  for (int i = (1); i < (n); i++) {
    if (a[i] - a[i - 1] == 1) {
      last[i] = last[i - 1];
    } else {
      last[i] = i;
    }
  }
  for (int i = (0); i < (m); i++) {
    cin >> b[i];
    pref[b[i]]++;
  }
  sort(b, b + m);
  for (int i = (1); i < (200000 + 1); i++) {
    pref[i] += pref[i - 1];
  }
  int ppp = n - 1;
  for (int j = (m - 1); j > (-1); j--) {
    while (ppp >= 0 && b[j] < a[last[ppp]]) {
      ppp = last[ppp] - 1;
    }
    first_pos[j] = ppp;
  }
  ppp = -1;
  for (int i = (0); i < (n); i++) {
    if (i + 1 < n && a[i + 1] - a[i] == 1) {
      continue;
    }
    while (ppp + 1 < m && b[ppp + 1] <= a[i]) {
      ppp++;
    }
    if (last[i] - 1 >= 0) {
      setmax(dp[i][0], max(dp[last[i] - 1][0], dp[last[i] - 1][1]));
      setmax(dp[i][1], max(dp[last[i] - 1][0], dp[last[i] - 1][1]));
    }
    int pos;
    for (int j = (ppp); j > (-1); j--) {
      int need = a[i] - b[j] + 1;
      pos = i - need + 1;
      if (pos < 0) {
        break;
      }
      pos = last[pos] - 1;
      setmax(dp[i][0], pref[a[i]] - pref[a[i] - (i - pos)] +
                           (pos >= 0 ? max(dp[pos][0], dp[pos][1]) : 0));
    }
    for (int j = (ppp); j > (-1); j--) {
      pos = first_pos[j];
      if (pos == -1) {
        break;
      }
      setmax(dp[i][1], dp[pos][0] + pref[a[pos] + (i - pos)] - pref[a[pos]]);
    }
  }
  cout << max(dp[n - 1][0], dp[n - 1][1]) << "\n";
  return 0;
}
