#include<bits/stdc++.h>
using namespace std;
int main() {
int n,k,counter,success,kc,complte;
cin >> n >> k;
int h[n];
int w[k];
for (int i = 0; i <n; i++) {
cin >> h[i];
}
for (int i = 0; i < k; i++) {
cin >> w[i];
}
while(1){
for(int i = 0; i < n; i++) {
if(h[i]>=counter+1){
for(int j = 0; j < w[kc]; j++){
if(h[i]>=counter+1){
success++;
i++;
if(success==w[kc]){
complte++;
break;
}
}
else{
i++;
break;
success=0;
}
}
kc++;
success=0;
}
}
if (complte<k){
break;
}
counter++;
kc=0;
}
cout<<counter<<endl;
system("pause");(送出時我有刪這行)
return 0;
}