#include <bits/stdc++.h>   using namespace std;   int n, m, a[100005], b[2005], d[100005], z[100005], L[100005];   inline void upd(int &a, int b) {     if (a < b) a = b;   }   int main(void) {     while (cin >> n >> m) {       for (int i = int(1); i <= int(n); i++) cin >> a[i];       for (int i = int(1); i <= int(m); i++) cin >> b[i];       sort(a + 1, a + n + 1);       sort(b + 1, b + m + 1);       memset(d, 0, sizeof d), memset(z, 0, sizeof z), memset(L, 0, sizeof L);       for (int i = int(1); i <= int(n); i++) {         if (i > 1 && a[i] - 1 == a[i - 1])           L[i] = L[i - 1];         else           L[i] = i;         int x = upper_bound(b + 1, b + m + 1, a[i]) - b;         upd(d[i], z[L[i] - 1]);         for (int j = int(x - 1); j >= int(1); j--) {           if (i <= a[i] - b[j]) break;           upd(d[i], z[L[i - a[i] + b[j]] - 1] + x - j);         }         upd(z[i], max(z[i - 1], d[i]));         for (int j = int(x); j <= int(m); j++) {           if (i + b[j] - a[i] > n) break;           upd(z[i + b[j] - a[i]], d[i] + j - x + 1);         }       }       cout << z[n] << endl;     }     return 0;   }   