#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int cmp(pair<int, int> a, pair<int, int> b) {
if (a.second == b.second) return a.first < b.first;
else return a.second < b.second;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int num_event, num_pc;
cin >> num_event >> num_pc;
vector<pair<int, int>> event(num_event);
for (int i = 0; i < num_event; i++) cin >> event[i].first;
for (int i = 0; i < num_event; i++) cin >> event[i].second;
sort(event.begin(), event.end(), cmp);
int ans = 0, which_pc_max = -10;
vector<int> pc_busy(num_pc, -1);
for (int i = 0; i < num_event; i++) {
for (int j = 0; j < num_pc; j++) {
if (pc_busy[j] < event[i].first && which_pc_max == -10) {
which_pc_max = j;
}
else if (pc_busy[j] < event[i].first && pc_busy[j] >= pc_busy[which_pc_max]) {
which_pc_max = j;
}
}
if (which_pc_max != -10) {
pc_busy[which_pc_max] = event[i].second;
ans++;
which_pc_max = -10;
}
}
cout << ans << '\n';
return 0;
}