/**
 * 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));
        }
        vector<unordered_map<int, int>> CacheL(B);
        vector<unordered_map<int, int>> CacheR(B);
        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));
            CacheL[b].clear();
            CacheR[b].clear();

            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;
                    if (Groups.back().lo < block[(int)block.size()-1].y) {
                        j = (int)block.size()-1;
                    } else {
                        auto it = CacheR[i].find(Groups.back().lo);
                        if (it != CacheR[i].end()) j = it->y;
                        else j = CacheR[i][Groups.back().lo] = 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 {
                                auto it = CacheL[last.blockId].find(BG.hi);
                                int s = (it != CacheL[last.blockId].find(BG.hi)) ? it->y : CacheL[last.blockId][BG.hi] = 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;

    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, 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 = min(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 = 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) 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 = 100;
        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;

    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));

//            for (int i = 0; i < B; ++i) {
//                for (auto c: Blocks[i].C) {
//                    cout << i << ' ' << c.lo << ' ' << c.hi << ' ' << c.i << ' ' << c.j << endl;
//                }
//            }

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

            int ans = 0;
            for (BlockGroup&bg: Groups) {
//                cout << bg.blockId << ' ' << bg.from << ' ' << bg.to << ' ' << bg.lo << ' ' << bg.hi << endl;
                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 = 512;
        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 = 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;
//            cout << A;
            build(Blocks[b], b*S, min(N, b*S+S));

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

//                cout << "HERE\n";
//                for (BlockGroup&bg: Groups) {
//                    cout << bg.blockId << ' ' << bg.from << ' '<< bg.to << ' ' << bg.lo << ' ' << bg.hi << endl;
//                }
//                cout << "HERE\n";

                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) {
//                cout << bg.blockId << ' ' << bg.from << ' '<< bg.to << ' ' << bg.lo << ' ' << bg.hi << endl;
                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, 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 = 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) 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(pair<vector<int>,vector<int>>&block, int from, int to) {
        block.x.clear();
        block.y.clear();
        for (int i = from; i < to; ++i) {
            int c = A[i], d = A[i];
            while (!block.x.empty() && block.x.back() < d) {
                c = min(block.x.back(), c);
                d = max(block.y.back(), d);
                block.x.pop_back();
                block.y.pop_back();
            }
            block.x.push_back(c);
            block.y.push_back(d);
        }
    }

    vector<pair<vector<int>, vector<int>>> 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.y[0]) {
                    Groups.push_back(BlockGroup{i, 0, (int)block.x.size(), block.x.back(), block.y[0]});
                } else {
                    int j = (Groups.back().lo < block.y.back()) ? (int)block.x.size()-1 : bsh(0, (int)block.x.size()-1, [&](int x) { return Groups.back().lo < block.y[x]; });
                    BlockGroup BG{-1, 0, 1, block.x.back(), block.y[0]};
                    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.x[last.from] < 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.x[last.to-1]);
                                BG.hi = max(BG.hi, lastB.y[s]);
                                last.lo = lastB.x[s-1];
                                last.hi = lastB.y[last.from];
                                last.to = s;
                            }
                        }
                    }
                    Groups.push_back(BG);
                    if (j+1 != (int)block.x.size()) {
                        Groups.push_back(BlockGroup{i, j+1, (int)block.x.size(), block.x.back(), block.y[j+1]});
                    }
                }
            }

            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 = 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 = lastB[s-1].x;
                                last.hi = lastB[last.from].y;
//                                for (int k = last.from; k < s; ++k) {
//                                    last.lo = min(last.lo, lastB[k].x);
//                                    last.hi = max(last.hi, lastB[k].y);
//                                }

                                BG.lo = min(BG.lo, lastB[last.to-1].x);
                                BG.hi = max(BG.hi, lastB[s].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];
                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;

    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 = 1025;
        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 = 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));
        }
        vector<map<int, int>> Cache(B);
        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));
            Cache[b].clear();

            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 {
                                auto it = Cache[last.blockId].find(BG.hi);
                                int s = (it != Cache[last.blockId].find(BG.hi)) ? it->y : Cache[last.blockId][BG.hi] = 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;

    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)Blocks[i].C.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 = max(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 = min(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));
        }
        vector<unordered_map<int, int>> Cache(B);
        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));
            Cache[b].clear();

            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 {
                                auto it = Cache[last.blockId].find(BG.hi);
                                int s = (it != Cache[last.blockId].find(BG.hi)) ? it->y : Cache[last.blockId][BG.hi] = 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;
}