#include <bits/stdc++.h>   #pragma GCC optimize(2)   #pragma GCC optimize(3)   #pragma GCC optimize( Ofast )   #pragma GCC optimize( inline )   #pragma GCC optimize( -fgcse )   #pragma GCC optimize( -fgcse-lm )   #pragma GCC optimize( -fipa-sra )   #pragma GCC optimize( -ftree-pre )   #pragma GCC optimize( -ftree-vrp )   #pragma GCC optimize( -fpeephole2 )   #pragma GCC optimize( -ffast-math )   #pragma GCC optimize( -fsched-spec )   #pragma GCC optimize( unroll-loops )   #pragma GCC optimize( -falign-jumps )   #pragma GCC optimize( -falign-loops )   #pragma GCC optimize( -falign-labels )   #pragma GCC optimize( -fdevirtualize )   #pragma GCC optimize( -fcaller-saves )   #pragma GCC optimize( -fcrossjumping )   #pragma GCC optimize( -fthread-jumps )   #pragma GCC optimize( -funroll-loops )   #pragma GCC optimize( -fwhole-program )   #pragma GCC optimize( -freorder-blocks )   #pragma GCC optimize( -fschedule-insns )   #pragma GCC optimize( inline-functions )   #pragma GCC optimize( -ftree-tail-merge )   #pragma GCC optimize( -fschedule-insns2 )   #pragma GCC optimize( -fstrict-aliasing )   #pragma GCC optimize( -fstrict-overflow )   #pragma GCC optimize( -falign-functions )   #pragma GCC optimize( -fcse-skip-blocks )   #pragma GCC optimize( -fcse-follow-jumps )   #pragma GCC optimize( -fsched-interblock )   #pragma GCC optimize( -fpartial-inlining )   #pragma GCC optimize( no-stack-protector )   #pragma GCC optimize( -freorder-functions )   #pragma GCC optimize( -findirect-inlining )   #pragma GCC optimize( -frerun-cse-after-loop )   #pragma GCC optimize( inline-small-functions )   #pragma GCC optimize( -finline-small-functions )   #pragma GCC optimize( -ftree-switch-conversion )   #pragma GCC optimize( -foptimize-sibling-calls )   #pragma GCC optimize( -fexpensive-optimizations )   #pragma GCC optimize( -funsafe-loop-optimizations )   #pragma GCC optimize( inline-functions-called-once )   #pragma GCC optimize( -fdelete-null-pointer-checks )   using namespace std;   inline long long read() {     long long x = 0, y = 0, c = getchar();     while (!isdigit(c)) y = c, c = getchar();     while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^  0 ), c = getchar();     return y ==  -  ? -x : x;   }   inline void print(long long q) {     if (q < 0) putchar( - ), q = -q;     if (q >= 10) print(q / 10);     putchar(q % 10 +  0 );   }   long long s1 = 19260817, s2 = 23333333, s3 = 998244353, srd;   inline long long rd() { return srd = (srd * s1 + s2 + rand()) % s3; }   void file() {     freopen( lis.in ,  r , stdin);     freopen( lis.out ,  w , stdout);   }   int n, m;   set<int> s;   int t[2][800010];   void ins(int op, int q, int l, int r, int ax, int x) {     if (l == r) {       t[op][q] = x;       return;     }     int mid = l + r >> 1;     if (mid >= ax)       ins(op, q << 1, l, mid, ax, x);     else       ins(op, q << 1 | 1, mid + 1, r, ax, x);     t[op][q] = max(t[op][q << 1], t[op][q << 1 | 1]);   }   int qy(int op, int q, int l, int r, int al, int ar) {     if (l >= al && r <= ar) return t[op][q];     int mid = l + r >> 1;     int as = 0;     if (mid >= al) as = qy(op, q << 1, l, mid, al, ar);     if (mid < ar) as = max(as, qy(op, q << 1 | 1, mid + 1, r, al, ar));     return as;   }   int gx(int op, int q) {     int tmp = qy(op, 1, 0, (!op ? n : m + 10), 0, q - 1) + 1;     ins(op, 1, 0, (!op ? n : m + 10), q, tmp);     return tmp;   }   int gd[200010], wz[200010];   int main() {     srand(time(0));     rd();     int i, j, op, x, y;     n = read();     m = read();     for (i = 1; i <= m; ++i) {       op = read();       x = read();       if (op == 1) {         y = read();         x = n - x + 1;         y = i - y + 10;         gd[x] = y;         wz[y] = x;         s.insert(x);         for (j = y + 1; j <= y + 9; ++j)           if (wz[j]) ins(0, 1, 0, n, wz[j], 0);         for (j = y; j <= y + 9; ++j)           if (wz[j]) {             int nxt = gx(0, wz[j]);             ins(1, 1, 0, m + 10, j, nxt);           }       } else {         set<int>::iterator it = s.end(), tp;         while (x--) {           --it;           ins(1, 1, 0, m + 10, gd[*it], 0);         }         tp = it;         ins(0, 1, 0, n, *it, 0);         wz[gd[*it]] = 0;         gd[*it] = 0;         for (++it; it != s.end(); ++it) {           int nxt = gx(1, gd[*it]);           ins(0, 1, 0, n, *it, nxt);         }         s.erase(tp);       }       print(t[0][1]);       putchar(  n );     }     return 0;   }