#include <bits/stdc++.h>
using namespace std;

bool gates[102400];

int main() {
    int g, p;
    cin >> g >> p;

    memset(gates, 0, sizeof(gates));

    int total = 0;;
    bool done = false;

    while (p--) {
        int x;
        cin >> x;
        if (done) continue;

        bool okay = false;

        for (int i = x; i >= 1; --i) {
            if (!gates[i]) {
                gates[i] = true;
                okay = true;
                ++total;
                break;
            }
        }

        if (!okay) {
            done = true;
        }
    }

    cout << total << endl;
}