Polycarp has just attempted to pass the driving test. He ran over the straight road with the signs of four types.

  * speed limit: this sign comes with a positive integer number — maximal speed of the car after the sign (cancel the action of the previous sign of this type); 
  * overtake is allowed: this sign means that after some car meets it, it can overtake any other car; 
  * no speed limit: this sign cancels speed limit if any (car can move with arbitrary speed after this sign); 
  * no overtake allowed: some car can't overtake any other car after this sign. 



Polycarp goes past the signs consequentially, each new sign cancels the action of all the previous signs of it's kind (speed limit/overtake). It is possible that two or more "no overtake allowed" signs go one after another with zero "overtake is allowed" signs between them. It works with "no speed limit" and "overtake is allowed" signs as well.

In the beginning of the ride overtake is allowed and there is no speed limit.

You are given the sequence of events in chronological order — events which happened to Polycarp during the ride. There are events of following types:

  1. Polycarp changes the speed of his car to specified (this event comes with a positive integer number); 
  2. Polycarp's car overtakes the other car; 
  3. Polycarp's car goes past the "speed limit" sign (this sign comes with a positive integer); 
  4. Polycarp's car goes past the "overtake is allowed" sign; 
  5. Polycarp's car goes past the "no speed limit"; 
  6. Polycarp's car goes past the "no overtake allowed"; 



It is guaranteed that the first event in chronological order is the event of type 1 (Polycarp changed the speed of his car to specified).

After the exam Polycarp can justify his rule violations by telling the driving instructor that he just didn't notice some of the signs. What is the minimal number of signs Polycarp should say he didn't notice, so that he would make no rule violations from his point of view?

Input

The first line contains one integer number n (1 ≤ n ≤ 2·105) — number of events.

Each of the next n lines starts with integer t (1 ≤ t ≤ 6) — the type of the event.

An integer s (1 ≤ s ≤ 300) follows in the query of the first and the third type (if it is the query of first type, then it's new speed of Polycarp's car, if it is the query of third type, then it's new speed limit).

It is guaranteed that the first event in chronological order is the event of type 1 (Polycarp changed the speed of his car to specified).

Output

Print the minimal number of road signs Polycarp should say he didn't notice, so that he would make no rule violations from his point of view.

Examples

Input

11
1 100
3 70
4
2
3 120
5
3 120
6
1 150
4
3 300


Output

2


Input

5
1 100
3 200
2
4
5


Output

0


Input

7
1 20
2
6
4
6
6
2


Output

2

Note

In the first example Polycarp should say he didn't notice the "speed limit" sign with the limit of 70 and the second "speed limit" sign with the limit of 120.

In the second example Polycarp didn't make any rule violation.

In the third example Polycarp should say he didn't notice both "no overtake allowed" that came after "overtake is allowed" sign.
/*
 * Author Ayub Subhaniya
 * Institute DA-IICT
 */

import java.io.*;
import java.math.*;
import java.util.*;

public class A
{
	
	InputStream in;
	PrintWriter out;
	
	long mod;
	int MAX=10001;
	void solve() 
	{
		int n=ni();
		Stack<Integer> speedLimit=new Stack<Integer>();
		Stack<Boolean> canOvertake=new Stack<Boolean>();
		int cnt=0;
		int curS=0;
		while (n-->0)
		{
			switch(ni())
			{
				case 1:
					int s=ni();
					curS=s;
					while (!speedLimit.isEmpty()&&s>speedLimit.peek())
					{
						cnt++;
						speedLimit.pop();
					}
					break;
				case 2:
					while (!canOvertake.isEmpty()&&canOvertake.peek()==false)
					{
						cnt++;
						canOvertake.pop();
					}
					break;
				case 3:
					s=ni();
					if (s<curS)
						cnt++;
					else
						speedLimit.push(s);
					break;
				case 4:
					canOvertake.push(true);
					break;
				case 5:
					speedLimit.push(MAX);
					break;
				case 6:
					canOvertake.push(false);
					break;
			}
		}
		out.println(cnt);
	}
	
	
	
	class Pair implements Comparable<Pair> {
		int x;
		int y;

		Pair(int a, int b) 
		{
			x = a;
			y = b;
		}

		@Override
		public boolean equals(Object o) 
		{
			Pair other = (Pair) o;
			return x == other.x && y == other.y;
		}

		public String toString() 
		{
			return x + " " + y;
		}

		@Override
		public int compareTo(Pair o) 
		{
			if (x == o.x)
				return Integer.compare(y, o.y);
			else
				return Integer.compare(x, o.x);
		}

		@Override
		public int hashCode() 
		{
			return Objects.hash(x, y);
		}
	}	
	long add(long a, long b) {
		long x = (a + b);
		while (x >= mod)
			x -= mod;
		return x;

	}

	long sub(long a, long b) {
		long x = (a - b);
		while (x < 0)
			x += mod;
		return x;

	}

	long mul(long a, long b) {
		a %= mod;
		b %= mod;
		long x = (a * b);
		return x % mod;

	}
	
	int max(int a, int b) {
		if (a > b)
			return a;
		else
			return b;
	}

	int min(int a, int b) {
		if (a > b)
			return b;
		else
			return a;
	}

	long max(long a, long b) {
		if (a > b)
			return a;
		else
			return b;

	}

	long min(long a, long b) {
		if (a > b)
			return b;
		else
			return a;

	}
	
	void run() throws Exception 
	{
		String INPUT = "C:/Users/ayubs/Desktop/input.txt";
		in = oj ? System.in : new FileInputStream(INPUT);
		out = new PrintWriter(System.out);
		
		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis() - s + "ms");
		
	}
	public static void main(String[] args) throws Exception 
	{
		new A().run();
	}
	
	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;
	
	private int readByte() 
	{
		if (lenbuf == -1)
			throw new InputMismatchException();
		if (ptrbuf >= lenbuf) 
		{
			ptrbuf = 0;
			try 
			{
				lenbuf = in.read(inbuf);
			}
			catch (IOException e) 
			{
				throw new InputMismatchException();
			}
			if (lenbuf <= 0)
				return -1;
		}
		return inbuf[ptrbuf++];
	}
	
	private boolean inSpaceChar(int c) 
	{
		return !(c >= 33 && c <= 126);
	}
	
	private int skip() 
	{
		int b;
		while ((b = readByte()) != -1 && inSpaceChar(b))
			;
		return b;
	}
	
	private double nd() 
	{
		return Double.parseDouble(ns());
	}
	
	private char nc() 
	{
		return (char) skip();
	}
	
	private String ns() 
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while (!(inSpaceChar(b))) 
		{ // when nextLine, (inSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	
	private char[] ns(int n) 
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while (p < n && !(inSpaceChar(b))) 
		{
			buf[p++] = (char) b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}
	
	private char[][] nm(int n, int m) 
	{
		char[][] map = new char[n][];
		for (int i = 0; i < n; i++)
			map[i] = ns(m);
		return map;
	}
	
	private int[] na(int n) 
	{
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	
	private int ni() 
	{
		int num = 0, b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') 
		{
			minus = true;
			b = readByte();
		}
		
		while (true) 
		{
			if (b >= '0' && b <= '9') 
			{
				num = num * 10 + (b - '0');
			} 
			else 
			{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}
	
	private long nl() 
	{
		long num = 0;
		int b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') 
		{
			minus = true;
			b = readByte();
		}
		
		while (true) 
		{
			if (b >= '0' && b <= '9') 
			{
				num = num * 10 + (b - '0');
			}
			else 
			{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}
	
	private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	
	private void tr(Object... o) 
	{
		if (!oj)
			System.out.println(Arrays.deepToString(o));
	}
	
}