using System; using System.Collections.Generic; using System.IO;
publicclassSum { publicstaticvoidMain() { var sr = new StreamReader(Console.OpenStandardInput()); var sw = new StreamWriter(Console.OpenStandardOutput()); var count = Convert.ToInt32(sr.ReadLine()); var leftFishs = new Stack<long>(); var left = 0; for (var i = 0; i < count; i++) { var input = sr.ReadLine().Split(' '); var dx = Convert.ToInt64(input[0]); var fx = Convert.ToInt32(input[1]); if (fx == 1) leftFishs.Push(dx); else while (true) if (leftFishs.Count > 0 && leftFishs.Peek() <= dx) leftFishs.Pop(); else { if (leftFishs.Count == 0) left++; break; } }