func_code_string: #include <bits/stdc++.h>   using namespace std;   const int INF = 1000000000;   int main() {     int n, m;     cin >> n >> m;     vector<int> session(n);     vector<vector<int> > s2d(m);     for (int i = 0; i < n; i++) {       cin >> session[i];       if (session[i]) s2d[session[i] - 1].push_back(i);     }     vector<int> price(m);     for (int i = 0; i < m; i++) {       cin >> price[i];     }     int l = 0, r = n, mid, cnt, doned;     vector<int> pos(m);     bool res, ares = false;     while (r - l > 1) {       mid = (l + r) / 2;       for (int i = 0; i < m; i++) {         pos[i] = (int)(upper_bound(s2d[i].begin(), s2d[i].end(), mid) -                        s2d[i].begin()) -                  1;         pos[i] = (pos[i] >= 0 ? s2d[i][pos[i]] : -1);       }       cnt = 0, doned = 0;       res = true;       for (int i = 0; i <= mid && res; i++) {         if (session[i] && pos[session[i] - 1] == i) {           cnt -= price[session[i] - 1];           doned++;         } else           cnt++;         if (cnt < 0) res = false;       }       if (!res || doned < m) {         l = mid;       } else {         r = mid;         ares = true;       }     }     if (ares)       cout << r + 1;     else       cout << -1;     return 0;   }   