#include<bits/stdc++.h> using namespace std; // g_i 에 가까이 앉는게 무조건 이득 int G, P; int R[111111]; int seat(int x) { // 도킹해야 할 자리 리턴 if (R[x] < 0) return x; return R[x] = seat(R[x]); } bool path(int x) { int x_seat = seat(x); // x가 도킹되야 할 자리 if (x_seat == 0) return false; // 도킹 자리 없는 경우 //x_seat 에 도킹했다 생각하고, 이 다음 비행기는 x_seat-1 에 앉아야한다. R[x_seat] = seat(x_seat - 1); return true; } int main() {ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); memset(R, -1, sizeof(R)); cin >> G >> P; int ans = 0; for (int i = 0; i < P; ++i) { int num; cin >> num; if (path(num)) ans++; else break; } cout << ans << '\n'; return 0; }