#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;

namespace IO {
    const int BUFFER_SIZE = 1 << 15;

    char input_buffer[BUFFER_SIZE];
    int input_pos = 0, input_len = 0;

    char output_buffer[BUFFER_SIZE];
    int output_pos = 0;

    char number_buffer[100];
    uint8_t lookup[100];

    void _update_input_buffer() {
        input_len = fread(input_buffer, sizeof(char), BUFFER_SIZE, stdin);
        input_pos = 0;

        if (input_len == 0)
            input_buffer[0] = EOF;
    }

    inline char next_char(bool advance = true) {
        if (input_pos >= input_len)
            _update_input_buffer();

        return input_buffer[advance ? input_pos++ : input_pos];
    }

    template<typename T>
    inline void read_int(T &number) {
        bool negative = false;
        number = 0;

        while (!isdigit(next_char(false)))
            if (next_char() == '-')
                negative = true;

        do {
            number = 10 * number + (next_char() - '0');
        } while (isdigit(next_char(false)));

        if (negative)
            number = -number;
    }

    template<typename T, typename... Args>
    inline void read_int(T &number, Args &... args) {
        read_int(number);
        read_int(args...);
    }

    void _flush_output() {
        fwrite(output_buffer, sizeof(char), output_pos, stdout);
        output_pos = 0;
    }

    inline void write_char(char c) {
        if (output_pos == BUFFER_SIZE)
            _flush_output();

        output_buffer[output_pos++] = c;
    }

    template<typename T>
    inline void write_int(T number, char after = '\0') {
        if (number < 0) {
            write_char('-');
            number = -number;
        }

        int length = 0;

        while (number >= 10) {
            uint8_t lookup_value = lookup[number % 100];
            number /= 100;
            number_buffer[length++] = (lookup_value & 15) + '0';
            number_buffer[length++] = (lookup_value >> 4) + '0';
        }

        if (number != 0 || length == 0)
            write_char(number + '0');

        for (int i = length - 1; i >= 0; i--)
            write_char(number_buffer[i]);

        if (after)
            write_char(after);
    }

    void init() {
        // Make sure _flush_output() is called at the end of the program.
        bool exit_success = atexit(_flush_output) == 0;
        assert(exit_success);

        for (int i = 0; i < 100; i++)
            lookup[i] = (i / 10 << 4) + i % 10;
    }
}

const int INF = 1e9 + 5;

struct segment_change {
    int to_add;
    bool toggle_active;

    segment_change(int _to_add = 0, bool _toggle_active = false) : to_add(_to_add), toggle_active(_toggle_active) {}

    void reset() {
        to_add = 0;
        toggle_active = false;
    }

    bool has_change() const {
        return to_add != 0 || toggle_active;
    }

    // Return the combined result of applying this segment change followed by `other`.
    segment_change combine(const segment_change &other) const {
        return segment_change(to_add + other.to_add, toggle_active ^ other.toggle_active);
    }
};

struct segment {
    int minimum, count_of_min;
    bool active;

    segment(int _minimum = INF, int _count_of_min = 0, bool _active = false)
        : minimum(_minimum), count_of_min(_count_of_min), active(_active) {}

    void apply(int, const segment_change &change) {
        minimum += change.to_add;
        active ^= change.toggle_active;
    }

    void join(const segment &other) {
        if (other.active) {
            if (!active || other.minimum < minimum)
                *this = other;
            else if (other.minimum == minimum)
                count_of_min += other.count_of_min;
        }
    }

    void join(const segment &a, const segment &b) {
        *this = a;
        join(b);
    }

    int get_goal_count(int goal) const {
        return (active && minimum == goal) ? count_of_min : 0;
    }
};

pair<int, int> right_half[32];

struct min_count_seg_tree {
    int tree_n = 0;
    vector<segment> tree;
    vector<segment_change> changes;

    min_count_seg_tree(int n = -1) {
        if (n >= 0)
            init(n);
    }

    void init(int n) {
        tree_n = 1;

        while (tree_n < n)
            tree_n *= 2;

        tree.assign(2 * tree_n, segment());
        changes.assign(tree_n, segment_change());
    }

    // Builds our tree from an array in O(n).
    void build(const vector<segment> &initial) {
        int n = initial.size();
        init(n);
        assert(n <= tree_n);

        for (int i = 0; i < n; i++)
            tree[tree_n + i] = initial[i];

        for (int position = tree_n - 1; position > 0; position--)
            tree[position].join(tree[2 * position], tree[2 * position + 1]);
    }

    void push_down(int position, int length) {
        if (!changes[position].has_change())
            return;

        if (2 * position < tree_n) {
            changes[2 * position] = changes[2 * position].combine(changes[position]);
            changes[2 * position + 1] = changes[2 * position + 1].combine(changes[position]);
        }

        tree[2 * position].apply(length / 2, changes[position]);
        tree[2 * position + 1].apply(length / 2, changes[position]);
        changes[position].reset();
    }

    // Calls push_down for all necessary nodes in order to query the range [a, b).
    void push_all(int a, int b) {
        assert(0 <= a && a < b && b <= tree_n);
        a += tree_n;
        b += tree_n - 1;

        for (int up = 31 - __builtin_clz(tree_n); up > 0; up--) {
            int x = a >> up, y = b >> up;
            push_down(x, 1 << up);
            if (x != y) push_down(y, 1 << up);
        }
    }

    void join_and_apply(int position, int length) {
        tree[position].join(tree[2 * position], tree[2 * position + 1]);
        tree[position].apply(length, changes[position]);
    }

    // Calls join for all necessary nodes after updating the range [a, b).
    void join_all(int a, int b) {
        assert(0 <= a && a < b && b <= tree_n);
        a += tree_n;
        b += tree_n - 1;
        int length = 1;

        while (a > 1) {
            a /= 2;
            b /= 2;
            length *= 2;
            join_and_apply(a, length);
            if (a != b) join_and_apply(b, length);
        }
    }

    template<typename T_range_op>
    void process_range(int a, int b, bool needs_join, T_range_op &&range_op) {
        if (a == b) return;
        push_all(a, b);
        int original_a = a, original_b = b;
        int length = 1, r_size = 0;

        for (a += tree_n, b += tree_n; a < b; a /= 2, b /= 2, length *= 2) {
            if (a & 1)
                range_op(a++, length);

            if (b & 1)
                right_half[r_size++] = {--b, length};
        }

        for (int i = r_size - 1; i >= 0; i--)
            range_op(right_half[i].first, right_half[i].second);

        if (needs_join)
            join_all(original_a, original_b);
    }

    segment query(int a, int b) {
        assert(0 <= a && a <= b && b <= tree_n);
        segment answer;

        process_range(a, b, false, [&](int position, int) {
            answer.join(tree[position]);
        });

        return answer;
    }

    void update(int a, int b, const segment_change &change) {
        assert(0 <= a && a <= b && b <= tree_n);

        process_range(a, b, true, [&](int position, int length) {
            tree[position].apply(length, change);

            if (position < tree_n)
                changes[position] = changes[position].combine(change);
        });
    }
};

const int MAX = 1e6 + 5;

int main() {
    IO::init();

    int N, Q;
    IO::read_int(N, Q);
    vector<int> A(N);

    for (int &a : A)
        IO::read_int(a);

    min_count_seg_tree tree(MAX);
    vector<segment> initial(MAX, segment(0, 1, false));

    for (int i = 0; i < N; i++)
        initial[A[i]].active = true;

    vector<int> delta(MAX, 0);

    for (int i = 0; i < N - 1; i++)
        if (A[i] < A[i + 1]) {
            delta[A[i]]++;
            delta[A[i + 1]]--;
        }

    int sum = 0;

    for (int i = 0; i < MAX; i++) {
        sum += delta[i];
        initial[i].minimum = sum;
    }

    tree.build(initial);

    for (int q = 0; q < Q; q++) {
        int position, x;
        IO::read_int(position, x);
        position--;

        tree.update(A[position], A[position] + 1, segment_change(0, true));
        if (position > 0 && A[position - 1] < A[position]) tree.update(A[position - 1], A[position], segment_change(-1));
        if (position < N - 1 && A[position] < A[position + 1]) tree.update(A[position], A[position + 1], segment_change(-1));

        A[position] = x;

        tree.update(A[position], A[position] + 1, segment_change(0, true));
        if (position > 0 && A[position - 1] < A[position]) tree.update(A[position - 1], A[position], segment_change(+1));
        if (position < N - 1 && A[position] < A[position + 1]) tree.update(A[position], A[position + 1], segment_change(+1));

        IO::write_int(tree.tree[1].get_goal_count(0), '\n');
    }
}


#include <bits/stdc++.h>

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

struct TRes {
    int l, r;
    int m, res;

    TRes operator+(const TRes &rhs) const {
//        cerr << l << ' ' << r << ' ' << m << ' ' << res << '\n';
//        cerr << rhs.l << ' ' << rhs.r << ' ' << rhs.m << ' ' << rhs.res << '\n';
        int gm = min(m, rhs.m);
        int nres = 0;
        if (m == gm) nres += res;
        if (rhs.m == gm) nres += rhs.res;
        if (r == gm && rhs.l > gm) ++nres;
//        cerr << gm << ' ' << nres << '\n';
        return {l, rhs.r, gm, nres};
    }
};

struct TNode {
    int L, R;
    int l, r;
    TRes res;
    int val;
};

const int maxt = 4100000, maxn = 510000;
TNode t[maxt];
int a[maxn];
int tc = 0;

#define dn TNode &n = t[node]

int buildTree(int L, int R) {
    int node = tc++;
    dn;
    n = {L, R, -1, -1, {0, 0, 0, 0}, 0};
    if (R - L > 1) {
        int M = (L + R) / 2;
        n.l = buildTree(L, M);
        n.r = buildTree(M, R);
    }
    return node;
}

void addval(int node, int val) {
    dn;
    n.res.l += val;
    n.res.r += val;
    n.res.m += val;
    n.val += val;
}

void push(int node) {
    dn;
    addval(n.l, n.val);
    addval(n.r, n.val);
    n.val = 0;
}

void addSeg(int node, int L, int R, int x) {
//    if (!node) cerr << L << ' ' << R << ' ' << x << '\n';
    dn;
    if (max(L, n.L) >= min(R, n.R)) return;
    if (L <= n.L && n.R <= R) {
        addval(node, x);
        return;
    }
    push(node);
    addSeg(n.l, L, R, x);
    addSeg(n.r, L, R, x);
    n.res = t[n.l].res + t[n.r].res;
}

int n, q;

void modify(int i, int delta) {
    if (i < 0) return;
    addSeg(0, 2 * a[i], 2 * max(a[i], a[i + 1]) + 1, delta);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
#endif

    cin >> n >> q;
    forn(i, n) cin >> a[i];
    a[n] = -1;
    buildTree(0, 2e6 + 2);
    forn(i, n) {
        modify(i, 1);
    }

/////////efwefwefww
//////////wwefwefwfew
//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew

//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew

//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew
//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

/////////efwefwefww
//////////wwefwefwfew
//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew

//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

/////////efwefwefww
//////////wwefwefwfew
//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew

//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew

//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew
//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

/////////efwefwefww
//////////wwefwefwfew
//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew

//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

    forn(i, q) {
        int p, x;
        cin >> p >> x;
        --p;
        forn(z, 2) modify(p - z, -1);
        a[p] = x;
        forn(z, 2) modify(p - z, 1);
        cout << t[0].res.res << '\n';
    }

/////////efwefwefww
//////////wwefwefwfew
//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew

//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew

//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew
//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

/////////efwefwefww
//////////wwefwefwfew
//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew

//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

/////////efwefwefww
//////////wwefwefwfew
//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew

//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew

//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew
//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

/////////efwefwefww
//////////wwefwefwfew
//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew

//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

/////////efwefwefww
//////////wwefwefwfew
//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew

//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew

//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew
//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

/////////efwefwefww
//////////wwefwefwfew
//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew

//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

/////////efwefwefww
//////////wwefwefwfew
//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew

//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew

//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew
//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

/////////efwefwefww
//////////wwefwefwfew
//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew

//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

/////////efwefwefww
//////////wwefwefwfew
//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew

//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew

//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew
//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

/////////efwefwefww
//////////wwefwefwfew
//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew

//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

/////////efwefwefww
//////////wwefwefwfew
//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew

//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew

//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew
//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

/////////efwefwefww
//////////wwefwefwfew
//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew

//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

/////////efwefwefww
//////////wwefwefwfew
//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew

//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew

//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew
//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

/////////efwefwefww
//////////wwefwefwfew
//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew

//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

/////////efwefwefww
//////////wwefwefwfew
//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew

//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew

//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew
//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

/////////efwefwefww
//////////wwefwefwfew
//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew

//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

/////////efwefwefww
//////////wwefwefwfew
//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew

//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew

//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew
//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

/////////efwefwefww
//////////wwefwefwfew
//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew

//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

/////////efwefwefww
//////////wwefwefwfew
//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew

//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew

//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew
//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

/////////efwefwefww
//////////wwefwefwfew
//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew

//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

/////////efwefwefww
//////////wwefwefwfew
//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew

//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew

//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew
//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

/////////efwefwefww
//////////wwefwefwfew
//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew

//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

/////////efwefwefww
//////////wwefwefwfew
//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew

//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew

//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew
//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

/////////efwefwefww
//////////wwefwefwfew
//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

//////////wefwefw//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew
//////////wefwefw
//////////ewfewefewe
//////////ewfwefwefw
//////////efwefwefww
//////////wwefwefwfew

//////////fwefwefwef
//////////wewefwefwef
//////////wefwefwef
//////////vwfwdwdwewef
//////////wefwefwefwef
//////////wewfwfwefew
//////////wewefwefwefew

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author majk
 */

#ifndef MAJK_LIB
#define MAJK_LIB

#include <vector>
#include <stack>
#include <iostream>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <iomanip>
#include <set>
#include <functional>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <cmath>
#include <string>
#include <queue>
#include <array>
#include <bitset>
using namespace std;

#define x first
#define y second
typedef std::pair<int,int> pii; typedef long long ll; typedef unsigned long long ull; typedef unsigned int ui; typedef pair<ui,ui> puu;

template <typename T, typename U> std::istream&operator>>(std::istream&i, pair<T,U>&p) {i >> p.x >> p.y; return i;}
template<typename T>std::istream&operator>>(std::istream&i,vector<T>&t) {for(auto&v:t){i>>v;}return i;}
template <typename T, typename U> std::ostream&operator<<(std::ostream&o, const pair<T,U>&p) {o << p.x << ' ' << p.y; return o;}
template<typename T>std::ostream&operator<<(std::ostream&o,const vector<T>&t) {if(t.empty())o<<'\n';for(size_t i=0;i<t.size();++i){o<<t[i]<<" \n"[i == t.size()-1];}return o;}
template<typename T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using maxheap = priority_queue<T, vector<T>, less<T>>;
ui logceil(ll x) { return x?8*sizeof(ll)-__builtin_clzll(x):0; }

namespace std { template<typename T,typename U>struct hash<pair<T,U>>{hash<T>t;hash<U>u;size_t operator()(const pair<T,U>&p)const{return t(p.x)^(u(p.y)<<7);}}; }
template<typename T,typename F>T bsh(T l,T h,const F&f){T r=-1,m;while(l<=h){m=(l+h)/2;if(f(m)){l=m+1;r=m;}else{h=m-1;}}return r;}
template<typename F> double bshd(double l,double h,const F&f,double p=1e-9){ui r=3+(ui)log2((h-l)/p);while(r--){double m=(l+h)/2;if(f(m)){l=m;}else{h=m;}}return (l+h)/2;}
template<typename T,typename F>T bsl(T l,T h,const F&f){T r=-1,m;while(l<=h){m=(l+h)/2;if(f(m)){h=m-1;r=m;}else{l=m+1;}}return r;}
template<typename F> double bsld(double l,double h,const F&f,double p=1e-9){ui r=3+(ui)log2((h-l)/p);while(r--){double m=(l+h)/2;if(f(m)){h=m;}else{l=m;}}return (l+h)/2;}
template<typename T> T gcd(T a,T b) { if (a<b) swap(a,b); return b?gcd(b,a%b):a; }

template<typename T>class vector2:public vector<vector<T>>{public:vector2(){} vector2(size_t a,size_t b,T t=T()):vector<vector<T>>(a,vector<T>(b,t)){}};
template<typename T>class vector3:public vector<vector2<T>>{public:vector3(){} vector3(size_t a,size_t b,size_t c,T t=T()):vector<vector2<T>>(a,vector2<T>(b,c,t)){}};
template<typename T>class vector4:public vector<vector3<T>>{public:vector4(){} vector4(size_t a,size_t b,size_t c,size_t d,T t=T()):vector<vector3<T>>(a,vector3<T>(b,c,d,t)){}};
template<typename T>class vector5:public vector<vector4<T>>{public:vector5(){} vector5(size_t a,size_t b,size_t c,size_t d,size_t e,T t=T()):vector<vector4<T>>(a,vector4<T>(b,c,d,e,t)){}};

#endif

class HNumberOfComponents {
public:
    int N, Q;
    vector<int> A;

    struct Comp {
        int i, j;
        int lo, hi;
    };

    struct Block {
        vector<Comp> C;
    };

    void build(Block&block, int from, int to) {
        block.C.clear();
        for (int i = from; i < to; ++i) {
            Comp c = {i,i,A[i],A[i]};
            while (!block.C.empty() && block.C.back().lo < c.hi) {
                c = {block.C.back().i, c.j, min(block.C.back().lo, c.lo), max(block.C.back().hi, c.hi)};
                block.C.pop_back();
            }
            block.C.push_back(c);
        }
    }

    vector<Block> Blocks;

    struct BlockGroup {
        int blockId;
        int from, to;
        int lo, hi;
    };

    void solve(istream& cin, ostream& cout) {
        cin >> N >> Q;
        A.resize(N);
        cin >> A;

        int S = 500;
        int B = (N+S-1)/S;
        Blocks.resize(B);
        for (int i = 0; i < B; ++i) {
            build(Blocks[i], i*S, min(i*S+S, N));
        }
        for (int q = 0; q < Q; ++q) {
            int p, x; cin >> p >> x;
            --p;
            int b = p/S;
            A[p] = x;
            build(Blocks[b], b*S, min(N, b*S+S));

            vector<BlockGroup> Groups;
            for (int i = 0; i < B; ++i) {
                auto &block = Blocks[i].C;
                int j = bsh(0, (int)block.size()-1, [&](int x) { return !Groups.empty() && Groups.back().lo < block[x].hi; });
                if (j == -1) {
                    Groups.push_back(BlockGroup{i, 0, (int)block.size(), block.back().lo, block[0].hi});
                } else {
                    BlockGroup BG{-1, 0, 1, block.back().lo, block[0].hi};
                    while (!Groups.empty() && Groups.back().lo < BG.hi) {
                        auto &last = Groups.back();
                        if (last.blockId == -1) {
                            BG.lo = min(BG.lo, last.lo);
                            BG.hi = max(BG.hi, last.hi);
                            Groups.pop_back();
                        } else {
                            auto &lastB = Blocks[last.blockId].C;
                            if (lastB[last.from].lo < BG.hi) {
                                BG.lo = min(BG.lo, last.lo);
                                BG.hi = max(BG.hi, last.hi);
                                Groups.pop_back();
                            } else {
                                int s = bsl(last.from, last.to - 1, [&](int x) { return lastB[x].lo < BG.hi; });
                                last.lo = 1000000000;
                                last.hi = 0;
                                last.to = s;
                                for (int k = last.from; k < s; ++k) {
                                    last.lo = min(last.lo, lastB[k].lo);
                                    last.hi = max(last.hi, lastB[k].hi);
                                }

                                for (int k = s; k < last.to; ++k) {
                                    BG.lo = min(BG.lo, lastB[k].lo);
                                    BG.hi = max(BG.hi, lastB[k].hi);
                                }
                            }
                        }
                    }
                    Groups.push_back(BG);
                    if (j+1 != (int)block.size()) {
                        Groups.push_back(BlockGroup{i, j+1, (int)block.size(), block.back().lo, block[j+1].hi});
                    }
                }
            }

            int ans = 0;
            for (BlockGroup&bg: Groups) ans += bg.to - bg.from;
            cout << ans << '\n';
        }
    }
};

int main() {
	ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	HNumberOfComponents solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
    return 0;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author majk
 */

#ifndef MAJK_LIB
#define MAJK_LIB

#include <vector>
#include <stack>
#include <iostream>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <iomanip>
#include <set>
#include <functional>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <cmath>
#include <string>
#include <queue>
#include <array>
#include <bitset>
using namespace std;

#define x first
#define y second
typedef std::pair<int,int> pii; typedef long long ll; typedef unsigned long long ull; typedef unsigned int ui; typedef pair<ui,ui> puu;

template <typename T, typename U> std::istream&operator>>(std::istream&i, pair<T,U>&p) {i >> p.x >> p.y; return i;}
template<typename T>std::istream&operator>>(std::istream&i,vector<T>&t) {for(auto&v:t){i>>v;}return i;}
template <typename T, typename U> std::ostream&operator<<(std::ostream&o, const pair<T,U>&p) {o << p.x << ' ' << p.y; return o;}
template<typename T>std::ostream&operator<<(std::ostream&o,const vector<T>&t) {if(t.empty())o<<'\n';for(size_t i=0;i<t.size();++i){o<<t[i]<<" \n"[i == t.size()-1];}return o;}
template<typename T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using maxheap = priority_queue<T, vector<T>, less<T>>;
ui logceil(ll x) { return x?8*sizeof(ll)-__builtin_clzll(x):0; }

namespace std { template<typename T,typename U>struct hash<pair<T,U>>{hash<T>t;hash<U>u;size_t operator()(const pair<T,U>&p)const{return t(p.x)^(u(p.y)<<7);}}; }
template<typename T,typename F>T bsh(T l,T h,const F&f){T r=-1,m;while(l<=h){m=(l+h)/2;if(f(m)){l=m+1;r=m;}else{h=m-1;}}return r;}
template<typename F> double bshd(double l,double h,const F&f,double p=1e-9){ui r=3+(ui)log2((h-l)/p);while(r--){double m=(l+h)/2;if(f(m)){l=m;}else{h=m;}}return (l+h)/2;}
template<typename T,typename F>T bsl(T l,T h,const F&f){T r=-1,m;while(l<=h){m=(l+h)/2;if(f(m)){h=m-1;r=m;}else{l=m+1;}}return r;}
template<typename F> double bsld(double l,double h,const F&f,double p=1e-9){ui r=3+(ui)log2((h-l)/p);while(r--){double m=(l+h)/2;if(f(m)){h=m;}else{l=m;}}return (l+h)/2;}
template<typename T> T gcd(T a,T b) { if (a<b) swap(a,b); return b?gcd(b,a%b):a; }

template<typename T>class vector2:public vector<vector<T>>{public:vector2(){} vector2(size_t a,size_t b,T t=T()):vector<vector<T>>(a,vector<T>(b,t)){}};
template<typename T>class vector3:public vector<vector2<T>>{public:vector3(){} vector3(size_t a,size_t b,size_t c,T t=T()):vector<vector2<T>>(a,vector2<T>(b,c,t)){}};
template<typename T>class vector4:public vector<vector3<T>>{public:vector4(){} vector4(size_t a,size_t b,size_t c,size_t d,T t=T()):vector<vector3<T>>(a,vector3<T>(b,c,d,t)){}};
template<typename T>class vector5:public vector<vector4<T>>{public:vector5(){} vector5(size_t a,size_t b,size_t c,size_t d,size_t e,T t=T()):vector<vector4<T>>(a,vector4<T>(b,c,d,e,t)){}};

#endif

class HNumberOfComponents {
public:
    int N, Q;
    vector<int> A;

    void build(vector<pii>&block, int from, int to) {
        block.clear();
        for (int i = from; i < to; ++i) {
            pii c = {A[i],A[i]};
            while (!block.empty() && block.back().x < c.y) {
                c = {min(block.back().x, c.x), max(block.back().y, c.y)};
                block.pop_back();
            }
            block.push_back(c);
        }
    }

    vector<vector<pii>> Blocks;

    struct BlockGroup {
        int blockId;
        int from, to;
        int lo, hi;
    };

    void solve(istream& cin, ostream& cout) {
        cin >> N >> Q;
        A.resize(N);
        cin >> A;

        int S = 1000;
        int B = (N+S-1)/S;
        Blocks.resize(B);
        for (int i = 0; i < B; ++i) {
            build(Blocks[i], i*S, min(i*S+S, N));
        }
        for (int q = 0; q < Q; ++q) {
            int p, x; cin >> p >> x;
            --p;
            int b = p/S;
            A[p] = x;
            build(Blocks[b], b*S, min(N, b*S+S));

            vector<BlockGroup> Groups;
            for (int i = 0; i < B; ++i) {

                auto &block = Blocks[i];
                if (Groups.empty() || Groups.back().lo >= block[0].y) {
                    Groups.push_back(BlockGroup{i, 0, (int)block.size(), block.back().x, block[0].y});
                } else {
                    int j = (!Groups.empty() && Groups.back().lo < block[(int)block.size()-1].y) ? (int)block.size()-1 : bsh(0, (int)block.size()-1, [&](int x) { return !Groups.empty() && Groups.back().lo < block[x].y; });
                    BlockGroup BG{-1, 0, 1, block.back().x, block[0].y};
                    while (!Groups.empty() && Groups.back().lo < BG.hi) {
                        auto &last = Groups.back();
                        if (last.blockId == -1) {
                            BG.lo = min(BG.lo, last.lo);
                            BG.hi = max(BG.hi, last.hi);
                            Groups.pop_back();
                        } else {
                            auto &lastB = Blocks[last.blockId];
                            if (lastB[last.from].x < BG.hi) {
                                BG.lo = min(BG.lo, last.lo);
                                BG.hi = max(BG.hi, last.hi);
                                Groups.pop_back();
                            } else {
                                int s = bsl(last.from, last.to - 1, [&](int x) { return lastB[x].x < BG.hi; });

                                BG.lo = min(BG.lo, lastB[last.to-1].x);
                                BG.hi = max(BG.hi, lastB[s].y);

                                last.lo = lastB[s-1].x;
                                last.hi = lastB[last.from].y;
                                last.to = s;
                            }
                        }
                    }
                    Groups.push_back(BG);
                    if (j+1 != (int)block.size()) {
                        Groups.push_back(BlockGroup{i, j+1, (int)block.size(), block.back().x, block[j+1].y});
                    }
                }
            }

            int ans = 0;
            for (BlockGroup&bg: Groups) ans += bg.to - bg.from;
            cout << ans << '\n';
        }
    }
};

int main() {
	ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	HNumberOfComponents solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
    return 0;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author majk
 */

#ifndef MAJK_LIB
#define MAJK_LIB

#include <vector>
#include <stack>
#include <iostream>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <iomanip>
#include <set>
#include <functional>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <cmath>
#include <string>
#include <queue>
#include <array>
#include <bitset>
using namespace std;

#define x first
#define y second
typedef std::pair<int,int> pii; typedef long long ll; typedef unsigned long long ull; typedef unsigned int ui; typedef pair<ui,ui> puu;

template <typename T, typename U> std::istream&operator>>(std::istream&i, pair<T,U>&p) {i >> p.x >> p.y; return i;}
template<typename T>std::istream&operator>>(std::istream&i,vector<T>&t) {for(auto&v:t){i>>v;}return i;}
template <typename T, typename U> std::ostream&operator<<(std::ostream&o, const pair<T,U>&p) {o << p.x << ' ' << p.y; return o;}
template<typename T>std::ostream&operator<<(std::ostream&o,const vector<T>&t) {if(t.empty())o<<'\n';for(size_t i=0;i<t.size();++i){o<<t[i]<<" \n"[i == t.size()-1];}return o;}
template<typename T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using maxheap = priority_queue<T, vector<T>, less<T>>;
ui logceil(ll x) { return x?8*sizeof(ll)-__builtin_clzll(x):0; }

namespace std { template<typename T,typename U>struct hash<pair<T,U>>{hash<T>t;hash<U>u;size_t operator()(const pair<T,U>&p)const{return t(p.x)^(u(p.y)<<7);}}; }
template<typename T,typename F>T bsh(T l,T h,const F&f){T r=-1,m;while(l<=h){m=(l+h)/2;if(f(m)){l=m+1;r=m;}else{h=m-1;}}return r;}
template<typename F> double bshd(double l,double h,const F&f,double p=1e-9){ui r=3+(ui)log2((h-l)/p);while(r--){double m=(l+h)/2;if(f(m)){l=m;}else{h=m;}}return (l+h)/2;}
template<typename T,typename F>T bsl(T l,T h,const F&f){T r=-1,m;while(l<=h){m=(l+h)/2;if(f(m)){h=m-1;r=m;}else{l=m+1;}}return r;}
template<typename F> double bsld(double l,double h,const F&f,double p=1e-9){ui r=3+(ui)log2((h-l)/p);while(r--){double m=(l+h)/2;if(f(m)){h=m;}else{l=m;}}return (l+h)/2;}
template<typename T> T gcd(T a,T b) { if (a<b) swap(a,b); return b?gcd(b,a%b):a; }

template<typename T>class vector2:public vector<vector<T>>{public:vector2(){} vector2(size_t a,size_t b,T t=T()):vector<vector<T>>(a,vector<T>(b,t)){}};
template<typename T>class vector3:public vector<vector2<T>>{public:vector3(){} vector3(size_t a,size_t b,size_t c,T t=T()):vector<vector2<T>>(a,vector2<T>(b,c,t)){}};
template<typename T>class vector4:public vector<vector3<T>>{public:vector4(){} vector4(size_t a,size_t b,size_t c,size_t d,T t=T()):vector<vector3<T>>(a,vector3<T>(b,c,d,t)){}};
template<typename T>class vector5:public vector<vector4<T>>{public:vector5(){} vector5(size_t a,size_t b,size_t c,size_t d,size_t e,T t=T()):vector<vector4<T>>(a,vector4<T>(b,c,d,e,t)){}};

#endif

class HNumberOfComponents {
public:
    int N, Q;
    vector<int> A;

    void build(vector<pii>&block, int from, int to) {
        block.clear();
        for (int i = from; i < to; ++i) {
            pii c = {A[i],A[i]};
            while (!block.empty() && block.back().x < c.y) {
                c = {min(block.back().x, c.x), max(block.back().y, c.y)};
                block.pop_back();
            }
            block.push_back(c);
        }
    }

    vector<vector<pii>> Blocks;

    struct BlockGroup {
        int blockId;
        int from, to;
        int lo, hi;
    };

    void solve(istream& cin, ostream& cout) {
        cin >> N >> Q;
        A.resize(N);
        cin >> A;

        int S = 513;
        int B = (N+S-1)/S;
        Blocks.resize(B);
        for (int i = 0; i < B; ++i) {
            build(Blocks[i], i*S, min(i*S+S, N));
        }
        for (int q = 0; q < Q; ++q) {
            int p, x; cin >> p >> x;
            --p;
            int b = p/S;
            A[p] = x;
            build(Blocks[b], b*S, min(N, b*S+S));

            vector<BlockGroup> Groups;
            for (int i = 0; i < B; ++i) {

                auto &block = Blocks[i];
                if (Groups.empty() || Groups.back().lo >= block[0].y) {
                    Groups.push_back(BlockGroup{i, 0, (int)block.size(), block.back().x, block[0].y});
                } else {
                    int j = (Groups.back().lo < block[(int)block.size()-1].y) ? (int)block.size()-1 : bsh(0, (int)block.size()-1, [&](int x) { return Groups.back().lo < block[x].y; });
                    BlockGroup BG{-1, 0, 1, block.back().x, block[0].y};
                    while (!Groups.empty() && Groups.back().lo < BG.hi) {
                        auto &last = Groups.back();
                        if (last.blockId == -1) {
                            BG.lo = min(BG.lo, last.lo);
                            BG.hi = max(BG.hi, last.hi);
                            Groups.pop_back();
                        } else {
                            auto &lastB = Blocks[last.blockId];
                            if (lastB[last.from].x < BG.hi) {
                                BG.lo = min(BG.lo, last.lo);
                                BG.hi = max(BG.hi, last.hi);
                                Groups.pop_back();
                            } else {
                                int s = bsl(last.from, last.to - 1, [&](int x) { return lastB[x].x < BG.hi; });
                                BG.lo = min(BG.lo, lastB[last.to-1].x);
                                BG.hi = max(BG.hi, lastB[s].y);
                                last.lo = lastB[s-1].x;
                                last.hi = lastB[last.from].y;
                                last.to = s;
                            }
                        }
                    }
                    Groups.push_back(BG);
                    if (j+1 != (int)block.size()) {
                        Groups.push_back(BlockGroup{i, j+1, (int)block.size(), block.back().x, block[j+1].y});
                    }
                }
            }

            int ans = 0;
            for (BlockGroup&bg: Groups) ans += bg.to - bg.from;
            cout << ans << '\n';
        }
    }
};

int main() {
	ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	HNumberOfComponents solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
    return 0;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author majk
 */

#ifndef MAJK_LIB
#define MAJK_LIB

#include <vector>
#include <stack>
#include <iostream>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <iomanip>
#include <set>
#include <functional>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <cmath>
#include <string>
#include <queue>
#include <array>
#include <bitset>
using namespace std;

#define x first
#define y second
typedef std::pair<int,int> pii; typedef long long ll; typedef unsigned long long ull; typedef unsigned int ui; typedef pair<ui,ui> puu;

template <typename T, typename U> std::istream&operator>>(std::istream&i, pair<T,U>&p) {i >> p.x >> p.y; return i;}
template<typename T>std::istream&operator>>(std::istream&i,vector<T>&t) {for(auto&v:t){i>>v;}return i;}
template <typename T, typename U> std::ostream&operator<<(std::ostream&o, const pair<T,U>&p) {o << p.x << ' ' << p.y; return o;}
template<typename T>std::ostream&operator<<(std::ostream&o,const vector<T>&t) {if(t.empty())o<<'\n';for(size_t i=0;i<t.size();++i){o<<t[i]<<" \n"[i == t.size()-1];}return o;}
template<typename T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using maxheap = priority_queue<T, vector<T>, less<T>>;
ui logceil(ll x) { return x?8*sizeof(ll)-__builtin_clzll(x):0; }

namespace std { template<typename T,typename U>struct hash<pair<T,U>>{hash<T>t;hash<U>u;size_t operator()(const pair<T,U>&p)const{return t(p.x)^(u(p.y)<<7);}}; }
template<typename T,typename F>T bsh(T l,T h,const F&f){T r=-1,m;while(l<=h){m=(l+h)/2;if(f(m)){l=m+1;r=m;}else{h=m-1;}}return r;}
template<typename F> double bshd(double l,double h,const F&f,double p=1e-9){ui r=3+(ui)log2((h-l)/p);while(r--){double m=(l+h)/2;if(f(m)){l=m;}else{h=m;}}return (l+h)/2;}
template<typename T,typename F>T bsl(T l,T h,const F&f){T r=-1,m;while(l<=h){m=(l+h)/2;if(f(m)){h=m-1;r=m;}else{l=m+1;}}return r;}
template<typename F> double bsld(double l,double h,const F&f,double p=1e-9){ui r=3+(ui)log2((h-l)/p);while(r--){double m=(l+h)/2;if(f(m)){h=m;}else{l=m;}}return (l+h)/2;}
template<typename T> T gcd(T a,T b) { if (a<b) swap(a,b); return b?gcd(b,a%b):a; }

template<typename T>class vector2:public vector<vector<T>>{public:vector2(){} vector2(size_t a,size_t b,T t=T()):vector<vector<T>>(a,vector<T>(b,t)){}};
template<typename T>class vector3:public vector<vector2<T>>{public:vector3(){} vector3(size_t a,size_t b,size_t c,T t=T()):vector<vector2<T>>(a,vector2<T>(b,c,t)){}};
template<typename T>class vector4:public vector<vector3<T>>{public:vector4(){} vector4(size_t a,size_t b,size_t c,size_t d,T t=T()):vector<vector3<T>>(a,vector3<T>(b,c,d,t)){}};
template<typename T>class vector5:public vector<vector4<T>>{public:vector5(){} vector5(size_t a,size_t b,size_t c,size_t d,size_t e,T t=T()):vector<vector4<T>>(a,vector4<T>(b,c,d,e,t)){}};

#endif

class HNumberOfComponents {
public:
    int N, Q;
    vector<int> A;

    void build(vector<pii>&block, int from, int to) {
        block.clear();
        for (int i = from; i < to; ++i) {
            pii c = {A[i],A[i]};
            while (!block.empty() && block.back().x < c.y) {
                c = {min(block.back().x, c.x), max(block.back().y, c.y)};
                block.pop_back();
            }
            block.push_back(c);
        }
    }

    vector<vector<pii>> Blocks;

    struct BlockGroup {
        int blockId;
        int from, to;
        int lo, hi;
    };

    void solve(istream& cin, ostream& cout) {
        cin >> N >> Q;
        A.resize(N);
        cin >> A;

        int S = 2000;
        int B = (N+S-1)/S;
        Blocks.resize(B);
        for (int i = 0; i < B; ++i) {
            build(Blocks[i], i*S, min(i*S+S, N));
        }
        for (int q = 0; q < Q; ++q) {
            int p, x; cin >> p >> x;
            --p;
            int b = p/S;
            A[p] = x;
            build(Blocks[b], b*S, min(N, b*S+S));

            vector<BlockGroup> Groups;
            for (int i = 0; i < B; ++i) {

                auto &block = Blocks[i];
                if (!(!Groups.empty() && Groups.back().lo < block[0].y)) {
                    Groups.push_back(BlockGroup{i, 0, (int)block.size(), block.back().x, block[0].y});
                } else {
                    int j = bsh(0, (int)block.size()-1, [&](int x) { return !Groups.empty() && Groups.back().lo < block[x].y; });
                    BlockGroup BG{-1, 0, 1, block.back().x, block[0].y};
                    while (!Groups.empty() && Groups.back().lo < BG.hi) {
                        auto &last = Groups.back();
                        if (last.blockId == -1) {
                            BG.lo = min(BG.lo, last.lo);
                            BG.hi = max(BG.hi, last.hi);
                            Groups.pop_back();
                        } else {
                            auto &lastB = Blocks[last.blockId];
                            if (lastB[last.from].x < BG.hi) {
                                BG.lo = min(BG.lo, last.lo);
                                BG.hi = max(BG.hi, last.hi);
                                Groups.pop_back();
                            } else {
                                int s = bsl(last.from, last.to - 1, [&](int x) { return lastB[x].x < BG.hi; });
                                last.lo = 1000000000;
                                last.hi = 0;

                                for (int k = last.from; k < s; ++k) {
                                    last.lo = min(last.lo, lastB[k].x);
                                    last.hi = max(last.hi, lastB[k].y);
                                }

                                for (int k = s; k < last.to; ++k) {
                                    BG.lo = min(BG.lo, lastB[k].x);
                                    BG.hi = max(BG.hi, lastB[k].y);
                                }
                                last.to = s;
                            }
                        }
                    }
                    Groups.push_back(BG);
                    if (j+1 != (int)block.size()) {
                        Groups.push_back(BlockGroup{i, j+1, (int)block.size(), block.back().x, block[j+1].y});
                    }
                }
            }

            int ans = 0;
            for (BlockGroup&bg: Groups) ans += bg.to - bg.from;
            cout << ans << '\n';
        }
    }
};

int main() {
	ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	HNumberOfComponents solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
    return 0;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author majk
 */

#ifndef MAJK_LIB
#define MAJK_LIB

#include <vector>
#include <stack>
#include <iostream>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <iomanip>
#include <set>
#include <functional>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <cmath>
#include <string>
#include <queue>
#include <array>
#include <bitset>
using namespace std;

#define x first
#define y second
typedef std::pair<int,int> pii; typedef long long ll; typedef unsigned long long ull; typedef unsigned int ui; typedef pair<ui,ui> puu;

template <typename T, typename U> std::istream&operator>>(std::istream&i, pair<T,U>&p) {i >> p.x >> p.y; return i;}
template<typename T>std::istream&operator>>(std::istream&i,vector<T>&t) {for(auto&v:t){i>>v;}return i;}
template <typename T, typename U> std::ostream&operator<<(std::ostream&o, const pair<T,U>&p) {o << p.x << ' ' << p.y; return o;}
template<typename T>std::ostream&operator<<(std::ostream&o,const vector<T>&t) {if(t.empty())o<<'\n';for(size_t i=0;i<t.size();++i){o<<t[i]<<" \n"[i == t.size()-1];}return o;}
template<typename T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using maxheap = priority_queue<T, vector<T>, less<T>>;
ui logceil(ll x) { return x?8*sizeof(ll)-__builtin_clzll(x):0; }

namespace std { template<typename T,typename U>struct hash<pair<T,U>>{hash<T>t;hash<U>u;size_t operator()(const pair<T,U>&p)const{return t(p.x)^(u(p.y)<<7);}}; }
template<typename T,typename F>T bsh(T l,T h,const F&f){T r=-1,m;while(l<=h){m=(l+h)/2;if(f(m)){l=m+1;r=m;}else{h=m-1;}}return r;}
template<typename F> double bshd(double l,double h,const F&f,double p=1e-9){ui r=3+(ui)log2((h-l)/p);while(r--){double m=(l+h)/2;if(f(m)){l=m;}else{h=m;}}return (l+h)/2;}
template<typename T,typename F>T bsl(T l,T h,const F&f){T r=-1,m;while(l<=h){m=(l+h)/2;if(f(m)){h=m-1;r=m;}else{l=m+1;}}return r;}
template<typename F> double bsld(double l,double h,const F&f,double p=1e-9){ui r=3+(ui)log2((h-l)/p);while(r--){double m=(l+h)/2;if(f(m)){h=m;}else{l=m;}}return (l+h)/2;}
template<typename T> T gcd(T a,T b) { if (a<b) swap(a,b); return b?gcd(b,a%b):a; }

template<typename T>class vector2:public vector<vector<T>>{public:vector2(){} vector2(size_t a,size_t b,T t=T()):vector<vector<T>>(a,vector<T>(b,t)){}};
template<typename T>class vector3:public vector<vector2<T>>{public:vector3(){} vector3(size_t a,size_t b,size_t c,T t=T()):vector<vector2<T>>(a,vector2<T>(b,c,t)){}};
template<typename T>class vector4:public vector<vector3<T>>{public:vector4(){} vector4(size_t a,size_t b,size_t c,size_t d,T t=T()):vector<vector3<T>>(a,vector3<T>(b,c,d,t)){}};
template<typename T>class vector5:public vector<vector4<T>>{public:vector5(){} vector5(size_t a,size_t b,size_t c,size_t d,size_t e,T t=T()):vector<vector4<T>>(a,vector4<T>(b,c,d,e,t)){}};

#endif

class HNumberOfComponents {
public:
    int N, Q;
    vector<int> A;

    struct Comp {
        int i, j;
        int lo, hi;
    };

    struct Block {
        vector<Comp> C;
    };

    void build(Block&block, int from, int to) {
        block.C.clear();
        for (int i = from; i < to; ++i) {
            Comp c = {i,i,A[i],A[i]};
            while (!block.C.empty() && block.C.back().lo < c.hi) {
                c = {block.C.back().i, c.j, min(block.C.back().lo, c.lo), max(block.C.back().hi, c.hi)};
                block.C.pop_back();
            }
            block.C.push_back(c);
        }
    }

    vector<Block> Blocks;

    struct BlockGroup {
        int blockId;
        int from, to;
        int lo, hi;
    };

    void solve(istream& cin, ostream& cout) {
        cin >> N >> Q;
        A.resize(N);
        cin >> A;

        int S = 2;
        int B = (N+S-1)/S;
        Blocks.resize(B);
        for (int i = 0; i < B; ++i) {
            build(Blocks[i], i*S, min(i*S+S, N));
        }
        for (int q = 0; q < Q; ++q) {
            int p, x; cin >> p >> x;
            --p;
            int b = p/S;
            A[p] = x;
            build(Blocks[b], b*S, min(N, b*S+S));

            vector<BlockGroup> Groups;
            for (int i = 0; i < B; ++i) {
                auto &block = Blocks[i].C;
                int j = bsh(0, (int)block.size()-1, [&](int x) { return !Groups.empty() && Groups.back().lo < block[x].hi; });
                if (j == -1) {
                    Groups.push_back(BlockGroup{i, 0, (int)block.size(), block.back().lo, block[0].hi});
                } else {
                    BlockGroup BG{-1, -1, -1, block.back().lo, block[0].hi};
                    while (!Groups.empty() && Groups.back().lo < BG.hi) {
                        auto &last = Groups.back();
                        auto &lastB = Blocks[last.blockId].C;
                        if (lastB[last.from].lo < BG.hi) {
                            BG.lo = min(BG.lo, last.lo);
                            BG.hi = min(BG.hi, last.hi);
                            Groups.pop_back();
                        } else {
                            int s = bsl(last.from, last.to-1, [&](int x) { return lastB[x].lo < BG.hi; });
                            last.lo = 100000000;
                            last.hi = 0;
                            last.to = s;
                            for (int k = 0; k < s; ++k) {
                                last.lo = min(last.lo, lastB[k].lo);
                                last.hi = max(last.hi, lastB[k].hi);
                            }

                            for (int k = s; k < last.to; ++k) {
                                BG.lo = min(BG.lo, lastB[k].lo);
                                BG.hi = max(BG.hi, lastB[k].hi);
                            }
                        }
                    }
                    Groups.push_back(BG);
                    if (j+1 != (int)block.size()) {
                        Groups.push_back(BlockGroup{i, j+1, (int)block.size(), block.back().lo, block[j+1].hi});
                    }
                }
            }

            int ans = 0;
            for (BlockGroup&bg: Groups) {
                if (bg.blockId == -1) ans++;
                else ans += bg.to - bg.from;
            }
            cout << ans << '\n';
        }
    }
};

int main() {
	ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	HNumberOfComponents solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
    return 0;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author majk
 */

#ifndef MAJK_LIB
#define MAJK_LIB

#include <vector>
#include <stack>
#include <iostream>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <iomanip>
#include <set>
#include <functional>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <cmath>
#include <string>
#include <queue>
#include <array>
#include <bitset>
using namespace std;

#define x first
#define y second
typedef std::pair<int,int> pii; typedef long long ll; typedef unsigned long long ull; typedef unsigned int ui; typedef pair<ui,ui> puu;

template <typename T, typename U> std::istream&operator>>(std::istream&i, pair<T,U>&p) {i >> p.x >> p.y; return i;}
template<typename T>std::istream&operator>>(std::istream&i,vector<T>&t) {for(auto&v:t){i>>v;}return i;}
template <typename T, typename U> std::ostream&operator<<(std::ostream&o, const pair<T,U>&p) {o << p.x << ' ' << p.y; return o;}
template<typename T>std::ostream&operator<<(std::ostream&o,const vector<T>&t) {if(t.empty())o<<'\n';for(size_t i=0;i<t.size();++i){o<<t[i]<<" \n"[i == t.size()-1];}return o;}
template<typename T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using maxheap = priority_queue<T, vector<T>, less<T>>;
ui logceil(ll x) { return x?8*sizeof(ll)-__builtin_clzll(x):0; }

namespace std { template<typename T,typename U>struct hash<pair<T,U>>{hash<T>t;hash<U>u;size_t operator()(const pair<T,U>&p)const{return t(p.x)^(u(p.y)<<7);}}; }
template<typename T,typename F>T bsh(T l,T h,const F&f){T r=-1,m;while(l<=h){m=(l+h)/2;if(f(m)){l=m+1;r=m;}else{h=m-1;}}return r;}
template<typename F> double bshd(double l,double h,const F&f,double p=1e-9){ui r=3+(ui)log2((h-l)/p);while(r--){double m=(l+h)/2;if(f(m)){l=m;}else{h=m;}}return (l+h)/2;}
template<typename T,typename F>T bsl(T l,T h,const F&f){T r=-1,m;while(l<=h){m=(l+h)/2;if(f(m)){h=m-1;r=m;}else{l=m+1;}}return r;}
template<typename F> double bsld(double l,double h,const F&f,double p=1e-9){ui r=3+(ui)log2((h-l)/p);while(r--){double m=(l+h)/2;if(f(m)){h=m;}else{l=m;}}return (l+h)/2;}
template<typename T> T gcd(T a,T b) { if (a<b) swap(a,b); return b?gcd(b,a%b):a; }

template<typename T>class vector2:public vector<vector<T>>{public:vector2(){} vector2(size_t a,size_t b,T t=T()):vector<vector<T>>(a,vector<T>(b,t)){}};
template<typename T>class vector3:public vector<vector2<T>>{public:vector3(){} vector3(size_t a,size_t b,size_t c,T t=T()):vector<vector2<T>>(a,vector2<T>(b,c,t)){}};
template<typename T>class vector4:public vector<vector3<T>>{public:vector4(){} vector4(size_t a,size_t b,size_t c,size_t d,T t=T()):vector<vector3<T>>(a,vector3<T>(b,c,d,t)){}};
template<typename T>class vector5:public vector<vector4<T>>{public:vector5(){} vector5(size_t a,size_t b,size_t c,size_t d,size_t e,T t=T()):vector<vector4<T>>(a,vector4<T>(b,c,d,e,t)){}};

#endif

class HNumberOfComponents {
public:
    int N, Q;
    vector<int> A;

    void build(vector<pii>&block, int from, int to) {
        block.clear();
        for (int i = from; i < to; ++i) {
            pii c = {A[i],A[i]};
            while (!block.empty() && block.back().x < c.y) {
                c = {min(block.back().x, c.x), max(block.back().y, c.y)};
                block.pop_back();
            }
            block.push_back(c);
        }
    }

    vector<vector<pii>> Blocks;

    struct BlockGroup {
        int blockId;
        int from, to;
        int lo, hi;
    };

    void solve(istream& cin, ostream& cout) {
        cin >> N >> Q;
        A.resize(N);
        cin >> A;

        int S = 1024;
        int B = (N+S-1)/S;
        Blocks.resize(B);
        for (int i = 0; i < B; ++i) {
            build(Blocks[i], i*S, min(i*S+S, N));
        }
        for (int q = 0; q < Q; ++q) {
            int p, x; cin >> p >> x;
            --p;
            int b = p/S;
            A[p] = x;
            build(Blocks[b], b*S, min(N, b*S+S));

            vector<BlockGroup> Groups;
            for (int i = 0; i < B; ++i) {

                auto &block = Blocks[i];
                if (Groups.empty() || Groups.back().lo >= block[0].y) {
                    Groups.push_back(BlockGroup{i, 0, (int)block.size(), block.back().x, block[0].y});
                } else {
                    int j = (Groups.back().lo < block[(int)block.size()-1].y) ? (int)block.size()-1 : bsh(0, (int)block.size()-1, [&](int x) { return Groups.back().lo < block[x].y; });
                    BlockGroup BG{-1, 0, 1, block.back().x, block[0].y};
                    while (!Groups.empty() && Groups.back().lo < BG.hi) {
                        auto &last = Groups.back();
                        if (last.blockId == -1) {
                            BG.lo = min(BG.lo, last.lo);
                            BG.hi = max(BG.hi, last.hi);
                            Groups.pop_back();
                        } else {
                            auto &lastB = Blocks[last.blockId];
                            if (lastB[last.from].x < BG.hi) {
                                BG.lo = min(BG.lo, last.lo);
                                BG.hi = max(BG.hi, last.hi);
                                Groups.pop_back();
                            } else {
                                int s = bsl(last.from, last.to - 1, [&](int x) { return lastB[x].x < BG.hi; });
                                BG.lo = min(BG.lo, lastB[last.to-1].x);
                                BG.hi = max(BG.hi, lastB[s].y);
                                last.lo = lastB[s-1].x;
                                last.hi = lastB[last.from].y;
                                last.to = s;
                            }
                        }
                    }
                    Groups.push_back(BG);
                    if (j+1 != (int)block.size()) {
                        Groups.push_back(BlockGroup{i, j+1, (int)block.size(), block.back().x, block[j+1].y});
                    }
                }
            }

            int ans = 0;
            for (BlockGroup&bg: Groups) ans += bg.to - bg.from;
            cout << ans << '\n';
        }
    }
};

int main() {
	ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	HNumberOfComponents solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
    return 0;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author majk
 */

#ifndef MAJK_LIB
#define MAJK_LIB

#include <vector>
#include <stack>
#include <iostream>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <iomanip>
#include <set>
#include <functional>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <cmath>
#include <string>
#include <queue>
#include <array>
#include <bitset>
using namespace std;

#define x first
#define y second
typedef std::pair<int,int> pii; typedef long long ll; typedef unsigned long long ull; typedef unsigned int ui; typedef pair<ui,ui> puu;

template <typename T, typename U> std::istream&operator>>(std::istream&i, pair<T,U>&p) {i >> p.x >> p.y; return i;}
template<typename T>std::istream&operator>>(std::istream&i,vector<T>&t) {for(auto&v:t){i>>v;}return i;}
template <typename T, typename U> std::ostream&operator<<(std::ostream&o, const pair<T,U>&p) {o << p.x << ' ' << p.y; return o;}
template<typename T>std::ostream&operator<<(std::ostream&o,const vector<T>&t) {if(t.empty())o<<'\n';for(size_t i=0;i<t.size();++i){o<<t[i]<<" \n"[i == t.size()-1];}return o;}
template<typename T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using maxheap = priority_queue<T, vector<T>, less<T>>;
ui logceil(ll x) { return x?8*sizeof(ll)-__builtin_clzll(x):0; }

namespace std { template<typename T,typename U>struct hash<pair<T,U>>{hash<T>t;hash<U>u;size_t operator()(const pair<T,U>&p)const{return t(p.x)^(u(p.y)<<7);}}; }
template<typename T,typename F>T bsh(T l,T h,const F&f){T r=-1,m;while(l<=h){m=(l+h)/2;if(f(m)){l=m+1;r=m;}else{h=m-1;}}return r;}
template<typename F> double bshd(double l,double h,const F&f,double p=1e-9){ui r=3+(ui)log2((h-l)/p);while(r--){double m=(l+h)/2;if(f(m)){l=m;}else{h=m;}}return (l+h)/2;}
template<typename T,typename F>T bsl(T l,T h,const F&f){T r=-1,m;while(l<=h){m=(l+h)/2;if(f(m)){h=m-1;r=m;}else{l=m+1;}}return r;}
template<typename F> double bsld(double l,double h,const F&f,double p=1e-9){ui r=3+(ui)log2((h-l)/p);while(r--){double m=(l+h)/2;if(f(m)){h=m;}else{l=m;}}return (l+h)/2;}
template<typename T> T gcd(T a,T b) { if (a<b) swap(a,b); return b?gcd(b,a%b):a; }

template<typename T>class vector2:public vector<vector<T>>{public:vector2(){} vector2(size_t a,size_t b,T t=T()):vector<vector<T>>(a,vector<T>(b,t)){}};
template<typename T>class vector3:public vector<vector2<T>>{public:vector3(){} vector3(size_t a,size_t b,size_t c,T t=T()):vector<vector2<T>>(a,vector2<T>(b,c,t)){}};
template<typename T>class vector4:public vector<vector3<T>>{public:vector4(){} vector4(size_t a,size_t b,size_t c,size_t d,T t=T()):vector<vector3<T>>(a,vector3<T>(b,c,d,t)){}};
template<typename T>class vector5:public vector<vector4<T>>{public:vector5(){} vector5(size_t a,size_t b,size_t c,size_t d,size_t e,T t=T()):vector<vector4<T>>(a,vector4<T>(b,c,d,e,t)){}};

#endif

class HNumberOfComponents {
public:
    int N, Q;
    vector<int> A;

    void build(vector<pii>&block, int from, int to) {
        block.clear();
        for (int i = from; i < to; ++i) {
            pii c = {A[i],A[i]};
            while (!block.empty() && block.back().x < c.y) {
                c = {min(block.back().x, c.x), max(block.back().y, c.y)};
                block.pop_back();
            }
            block.push_back(c);
        }
    }

    vector<vector<pii>> Blocks;

    struct BlockGroup {
        int blockId;
        int from, to;
        int lo, hi;
    };

    void solve(istream& cin, ostream& cout) {
        cin >> N >> Q;
        A.resize(N);
        cin >> A;

        int S = 1000;
        int B = (N+S-1)/S;
        Blocks.resize(B);
        for (int i = 0; i < B; ++i) {
            build(Blocks[i], i*S, min(i*S+S, N));
        }
        for (int q = 0; q < Q; ++q) {
            int p, x; cin >> p >> x;
            --p;
            int b = p/S;
            A[p] = x;
            build(Blocks[b], b*S, min(N, b*S+S));

            vector<BlockGroup> Groups;
            for (int i = 0; i < B; ++i) {

                auto &block = Blocks[i];
                int j = bsh(0, (int)block.size()-1, [&](int x) { return !Groups.empty() && Groups.back().lo < block[x].y; });
                if (j == -1) {
                    Groups.push_back(BlockGroup{i, 0, (int)block.size(), block.back().x, block[0].y});
                } else {
                    BlockGroup BG{-1, 0, 1, block.back().x, block[0].y};
                    while (!Groups.empty() && Groups.back().lo < BG.hi) {
                        auto &last = Groups.back();
                        if (last.blockId == -1) {
                            BG.lo = min(BG.lo, last.lo);
                            BG.hi = max(BG.hi, last.hi);
                            Groups.pop_back();
                        } else {
                            auto &lastB = Blocks[last.blockId];
                            if (lastB[last.from].x < BG.hi) {
                                BG.lo = min(BG.lo, last.lo);
                                BG.hi = max(BG.hi, last.hi);
                                Groups.pop_back();
                            } else {
                                int s = bsl(last.from, last.to - 1, [&](int x) { return lastB[x].x < BG.hi; });
                                last.lo = 1000000000;
                                last.hi = 0;

                                for (int k = last.from; k < s; ++k) {
                                    last.lo = min(last.lo, lastB[k].x);
                                    last.hi = max(last.hi, lastB[k].y);
                                }

                                for (int k = s; k < last.to; ++k) {
                                    BG.lo = min(BG.lo, lastB[k].x);
                                    BG.hi = max(BG.hi, lastB[k].y);
                                }
                                last.to = s;
                            }
                        }
                    }
                    Groups.push_back(BG);
                    if (j+1 != (int)block.size()) {
                        Groups.push_back(BlockGroup{i, j+1, (int)block.size(), block.back().x, block[j+1].y});
                    }
                }
            }

            int ans = 0;
            for (BlockGroup&bg: Groups) ans += bg.to - bg.from;
            cout << ans << '\n';
        }
    }
};

int main() {
	ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	HNumberOfComponents solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
    return 0;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author majk
 */

#ifndef MAJK_LIB
#define MAJK_LIB

#include <vector>
#include <stack>
#include <iostream>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <iomanip>
#include <set>
#include <functional>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <cmath>
#include <string>
#include <queue>
#include <array>
#include <bitset>
using namespace std;

#define x first
#define y second
typedef std::pair<int,int> pii; typedef long long ll; typedef unsigned long long ull; typedef unsigned int ui; typedef pair<ui,ui> puu;

template <typename T, typename U> std::istream&operator>>(std::istream&i, pair<T,U>&p) {i >> p.x >> p.y; return i;}
template<typename T>std::istream&operator>>(std::istream&i,vector<T>&t) {for(auto&v:t){i>>v;}return i;}
template <typename T, typename U> std::ostream&operator<<(std::ostream&o, const pair<T,U>&p) {o << p.x << ' ' << p.y; return o;}
template<typename T>std::ostream&operator<<(std::ostream&o,const vector<T>&t) {if(t.empty())o<<'\n';for(size_t i=0;i<t.size();++i){o<<t[i]<<" \n"[i == t.size()-1];}return o;}
template<typename T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using maxheap = priority_queue<T, vector<T>, less<T>>;
ui logceil(ll x) { return x?8*sizeof(ll)-__builtin_clzll(x):0; }

namespace std { template<typename T,typename U>struct hash<pair<T,U>>{hash<T>t;hash<U>u;size_t operator()(const pair<T,U>&p)const{return t(p.x)^(u(p.y)<<7);}}; }
template<typename T,typename F>T bsh(T l,T h,const F&f){T r=-1,m;while(l<=h){m=(l+h)/2;if(f(m)){l=m+1;r=m;}else{h=m-1;}}return r;}
template<typename F> double bshd(double l,double h,const F&f,double p=1e-9){ui r=3+(ui)log2((h-l)/p);while(r--){double m=(l+h)/2;if(f(m)){l=m;}else{h=m;}}return (l+h)/2;}
template<typename T,typename F>T bsl(T l,T h,const F&f){T r=-1,m;while(l<=h){m=(l+h)/2;if(f(m)){h=m-1;r=m;}else{l=m+1;}}return r;}
template<typename F> double bsld(double l,double h,const F&f,double p=1e-9){ui r=3+(ui)log2((h-l)/p);while(r--){double m=(l+h)/2;if(f(m)){h=m;}else{l=m;}}return (l+h)/2;}
template<typename T> T gcd(T a,T b) { if (a<b) swap(a,b); return b?gcd(b,a%b):a; }

template<typename T>class vector2:public vector<vector<T>>{public:vector2(){} vector2(size_t a,size_t b,T t=T()):vector<vector<T>>(a,vector<T>(b,t)){}};
template<typename T>class vector3:public vector<vector2<T>>{public:vector3(){} vector3(size_t a,size_t b,size_t c,T t=T()):vector<vector2<T>>(a,vector2<T>(b,c,t)){}};
template<typename T>class vector4:public vector<vector3<T>>{public:vector4(){} vector4(size_t a,size_t b,size_t c,size_t d,T t=T()):vector<vector3<T>>(a,vector3<T>(b,c,d,t)){}};
template<typename T>class vector5:public vector<vector4<T>>{public:vector5(){} vector5(size_t a,size_t b,size_t c,size_t d,size_t e,T t=T()):vector<vector4<T>>(a,vector4<T>(b,c,d,e,t)){}};

#endif

class HNumberOfComponents {
public:
    int N, Q;
    vector<int> A;

    void build(vector<pii>&block, int from, int to) {
        block.clear();
        for (int i = from; i < to; ++i) {
            pii c = {A[i],A[i]};
            while (!block.empty() && block.back().x < c.y) {
                c = {min(block.back().x, c.x), max(block.back().y, c.y)};
                block.pop_back();
            }
            block.push_back(c);
        }
    }

    vector<vector<pii>> Blocks;

    struct BlockGroup {
        int blockId;
        int from, to;
        int lo, hi;
    };

    void solve(istream& cin, ostream& cout) {
        cin >> N >> Q;
        A.resize(N);
        cin >> A;

        int S = 2048;
        int B = (N+S-1)/S;
        Blocks.resize(B);
        for (int i = 0; i < B; ++i) {
            build(Blocks[i], i*S, min(i*S+S, N));
        }
        for (int q = 0; q < Q; ++q) {
            int p, x; cin >> p >> x;
            --p;
            int b = p/S;
            A[p] = x;
            build(Blocks[b], b*S, min(N, b*S+S));

            vector<BlockGroup> Groups;
            for (int i = 0; i < B; ++i) {

                auto &block = Blocks[i];
                if (Groups.empty() || Groups.back().lo >= block[0].y) {
                    Groups.push_back(BlockGroup{i, 0, (int)block.size(), block.back().x, block[0].y});
                } else {
                    int j = (Groups.back().lo < block[(int)block.size()-1].y) ? (int)block.size()-1 : bsh(0, (int)block.size()-1, [&](int x) { return Groups.back().lo < block[x].y; });
                    BlockGroup BG{-1, 0, 1, block.back().x, block[0].y};
                    while (!Groups.empty() && Groups.back().lo < BG.hi) {
                        auto &last = Groups.back();
                        if (last.blockId == -1) {
                            BG.lo = min(BG.lo, last.lo);
                            BG.hi = max(BG.hi, last.hi);
                            Groups.pop_back();
                        } else {
                            auto &lastB = Blocks[last.blockId];
                            if (lastB[last.from].x < BG.hi) {
                                BG.lo = min(BG.lo, last.lo);
                                BG.hi = max(BG.hi, last.hi);
                                Groups.pop_back();
                            } else {
                                int s = bsl(last.from, last.to - 1, [&](int x) { return lastB[x].x < BG.hi; });
                                BG.lo = min(BG.lo, lastB[last.to-1].x);
                                BG.hi = max(BG.hi, lastB[s].y);
                                last.lo = lastB[s-1].x;
                                last.hi = lastB[last.from].y;
                                last.to = s;
                            }
                        }
                    }
                    Groups.push_back(BG);
                    if (j+1 != (int)block.size()) {
                        Groups.push_back(BlockGroup{i, j+1, (int)block.size(), block.back().x, block[j+1].y});
                    }
                }
            }

            int ans = 0;
            for (BlockGroup&bg: Groups) ans += bg.to - bg.from;
            cout << ans << '\n';
        }
    }
};

int main() {
	ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	HNumberOfComponents solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
    return 0;
}