Under construction

Still being built. Things may change

Entry Records

Interview

Time limit1sMemory limit1024 MB

Summary
Given today's ordered entry and exit records, find the fewest records that must be missing so each person's enter and leave events alternate correctly.
Level

Easy3 of 10

Topics
Hash map, Implementation
Solved
No attempts yet

Problem

A military police officer at a guard post finished the day shift and went through today's entry records for a security check. He realized that some of today's entry records are missing.

Today's entry records total NN, and the records are always written in the order in which people entered or left.

The ii-th entry record is written as two integers aia_i and bib_i. aia_i is the number of the person entering or leaving. If bib_i is 11, the person entered the base. If bib_i is 00, the person left the base. Before the first record and after the last record, nobody was inside the base.

Using today's entry records, find the minimum number of missing entry records over the whole day.

Input

The first line contains the number of entry records NN. (1≤N≤200 0001 \leq N \leq 200\,000)

From the second line through line N+1N+1, the ii-th entry record is given as the integers aia_i and bib_i, separated by a space. (1≤ai≤200 0001 \leq a_i \leq 200\,000, 0≤bi≤10 \leq b_i \leq 1)

Output

Print the minimum number of entry records that were missing during the day.

Examples2

  1. Example 1

    Input
    8
    1 1
    2 1
    1 1
    4 1
    3 0
    5 1
    4 0
    1 0
    
    Expected output
    4
    
  2. Example 2

    Input
    4
    100 1
    345 1
    345 0
    100 0
    
    Expected output
    0