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.
import java.io.*;
import java.util.*;

import static java.lang.Math.*;
import static java.util.Arrays.sort;

public class Main {

    private static final int INF = 1000000000;
    private static final double EPS = 0.00000001;

    static BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer in = null;
    static PrintWriter out = new PrintWriter(System.out);

    static int nextInt() {
        return Integer.parseInt(nextToken());
    }

    static long nextLong() {
        return Long.parseLong(nextToken());
    }

    static double nextDouble() {
        return Double.parseDouble(nextToken());
    }

    static String nextToken() {
        while ((in == null) || !in.hasMoreTokens()) {
            try {
                in = new StringTokenizer(rd.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return in.nextToken();
    }

    static int binarysearch(int min, int max, function1<Boolean, Integer> f) {
        int l = min;
        int r = max;
        while (r - l >= 1) {
            int m = (l + r) / 2;
            boolean b = f.f(m);
            if (b) {
                r = m;
            } else {
                l = m + 1;
            }
        }
        return l;
    }

    static interface function1<T1, T2> {
        T1 f(T2 m);
    }

    static interface function2<T1, T2, T3> {
        T1 f(T2 first, T3 second);
    }

    static class Pair implements Comparable<Pair> {
        double first, second;

        public Pair(double first, double second) {
            this.first = first;
            this.second = second;
        }

        @Override
        public int compareTo(Pair o) {
            return ((Double) first).compareTo(o.first) == 0 ? ((Double) second).compareTo(o.second) : ((Double) first).compareTo(o.first);
        }
    }

    static class Point {
        private double x, y;

        public double getX() {
            return x;
        }

        public double getY() {
            return y;
        }

        public Point(double x, double y) {
            this.x = x;
            this.y = y;
        }

        public double distance(Point p) {
            return Math.sqrt((x - p.x) * (x - p.x) + (y - p.y) * (y - p.y));
        }

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

    static class Cyrcle {
        double x, y, r;

        public Point Center() {
            return new Point(x, y);
        }


        public Cyrcle(double x, double y, double r) {
            this.x = x;
            this.y = y;
            this.r = r;
        }

        public Cyrcle(Point center, double r) {
            this.x = center.getX();
            this.y = center.getY();
            this.r = r;
        }

        public double Sqr() {
            return PI * r * r;
        }

        public double getR() {
            return r;
        }
    }

    private static final Point zeroPoint = new Point(0, 0);

    static class Vector {
        private double x, y;

        public Vector(Point start, Point end) {
            this.x = end.x - start.x;
            this.y = end.y - start.y;
        }

        public double vect(Vector o) {
            return getX() * o.getY() - o.getX() * getY();
        }

        public double scal(Vector o) {
            return getX() * o.getX() + getY() * o.getY();
        }

        public double getX() {
            return x;
        }

        public double getY() {
            return y;
        }

        public double sqr(Vector o) {
            return o.vect(this) / 2;
        }

        public static double atan2(double vect, double scal) {
            return Math.atan2(vect, scal);
        }
    }

    static class Segment {
        Point start, end;

        public Segment(Point start, Point end) {
            this.start = start;
            this.end = end;
        }

        public Segment(double x1, double y1, double x2, double y2) {
            this.start = new Point(x1, y1);
            this.end = new Point(x2, y2);
        }

        public Pair getEquation() {
            return new Pair((start.getX() - end.getX()) / (start.getY() - end.getY()),
                    start.getX() - ((start.getX() - end.getX()) / (start.getY() - end.getY())) * start.getY());
        }

        public Point getStart() {
            return start;
        }

        public Point getEnd() {
            return end;
        }

        public static double atan2(Segment o1, Segment o2) {
            Vector vo1 = new Vector(o1.start, o1.end);
            Vector vo2 = new Vector(o2.start, o2.end);
            return Vector.atan2(vo1.vect(vo2), vo1.scal(vo2));
        }

        public static Point isIntersect(Segment o1, Segment o2) {
            boolean b1 = false;
            if (o1.start.getX() <= o2.start.getX()
                    && o1.start.getX() <= o2.end.getX()
                    && o2.start.getX() <= o1.end.getX()
                    && o2.end.getX() <= o1.end.getX()) {
                b1 = true;
            }
            boolean b2 = false;
            if (o2.start.getX() <= o1.start.getX()
                    && o2.start.getX() <= o1.end.getX()
                    && o1.start.getX() <= o2.end.getX()
                    && o1.end.getX() <= o2.end.getX()) {
                b2 = true;
            }
            boolean b3 = false;
            if (o1.start.getY() <= o2.start.getY()
                    && o1.start.getY() <= o2.end.getY()
                    && o2.start.getY() <= o1.end.getY()
                    && o2.end.getY() <= o1.end.getY()) {
                b3 = true;
            }
            boolean b4 = false;
            if (o2.start.getY() <= o1.start.getY()
                    && o2.start.getY() <= o1.end.getY()
                    && o1.start.getY() <= o2.end.getY()
                    && o1.end.getY() <= o2.end.getY()) {
                b4 = true;
            }
            if (!((b1 || b2) && (b3 || b4))) {
                return zeroPoint;
            }
            return null;
        }
    }

    static class Line {
        Point start, end;

        public Line(Point start, Point end) {
            this.start = start;
            this.end = end;
        }

        public Line(double x1, double y1, double x2, double y2) {
            this.start = new Point(x1, y1);
            this.end = new Point(x2, y2);
        }

        public Pair getEquation() {
            if (start.getX() == end.getX()) {
                return new Pair(Double.NaN, Double.NaN);
            }
            double k = ((start.getY() - end.getY()) / (start.getX() - end.getX()));
            return new Pair(k,
                    start.getY() - k * start.getX());
        }

        public Point getStart() {
            return start;
        }

        public Point getEnd() {
            return end;
        }

        public static double atan2(Segment o1, Segment o2) {
            Vector vo1 = new Vector(o1.start, o1.end);
            Vector vo2 = new Vector(o2.start, o2.end);
            return Vector.atan2(vo1.vect(vo2), vo1.scal(vo2));
        }

        public Point getPointRestraint(Line o) {
            Pair p1 = getEquation();
            Pair p2 = o.getEquation();
            if (p1.compareTo(new Pair(Double.NaN, Double.NaN)) == 0) {
                return new Point(getEnd().getX(), getEnd().getX() * p2.first + p2.second);
            }
            if (p2.compareTo(new Pair(Double.NaN, Double.NaN)) == 0) {
                return new Point(o.getEnd().getX(), o.getEnd().getX() * p1.first + p1.second);
            }
            Point point = new Point((p1.second - p2.second) / (p2.first - p1.first), 0);
            return new Point(point.getX(), point.getX() * p1.first + p1.second);
        }

        @Override
        public String toString() {
            return start + " | " + end;
        }
    }

    static class Polygon {
        Point[] vertexs;

        public Polygon(Point[] vertexs) {
            this.vertexs = vertexs;
        }

        public Polygon(int[] x, int[] y) {
            for (int i = 0; i < x.length; i++) {
                this.vertexs[i] = new Point(x[i], y[i]);
            }
        }

        public Segment getSegment(int i) {
            return new Segment(vertexs[i], vertexs[(i + 1) % vertexs.length]);
        }
    }

    static class SegmentationTree {
        int t[];
        function2<Integer, Integer, Integer> f;
        int default_value;

        public SegmentationTree(int maxSize, function2<Integer, Integer, Integer> f, int default_value) {
            t = new int[maxSize * 4];
            this.f = f;
            this.default_value = default_value;
        }

        public void build(int[] a) {
            build(a, 1, 0, t.length / 4 - 1);
        }

        private void build(int a[], int v, int tl, int tr) {
            if (tl == tr)
                t[v] = (a[tl]);
            else {
                int tm = (tl + tr) / 2;
                build(a, v * 2, tl, tm);
                build(a, v * 2 + 1, tm + 1, tr);
                t[v] = f.f(t[v * 2], t[v * 2 + 1]);
            }
        }

        public int get_f(int l, int r) {
            return get_f(1, 0, t.length / 4 - 1, l, r);
        }

        private int get_f(int v, int tl, int tr, int l, int r) {
            if (l > r)
                return default_value;
            if (l == tl && r == tr)
                return t[v];
            int tm = (tl + tr) / 2;
            return f.f(
                    get_f(v * 2, tl, tm, l, min(r, tm)),
                    get_f(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r)
            );
        }

        public void update(int pos, int new_val) {
            update(1, 0, t.length / 4 - 1, pos, new_val);
        }

        private void update(int v, int tl, int tr, int pos, int new_val) {
            if (tl == tr)
                t[v] = new_val;
            else {
                int tm = (tl + tr) / 2;
                if (pos <= tm)
                    update(v * 2, tl, tm, pos, new_val);
                else
                    update(v * 2 + 1, tm + 1, tr, pos, new_val);
                t[v] = f.f(t[v * 2], t[v * 2 + 1]);
            }
        }
    }

    static int getMaxSegment(int[] a) {
        int tmp = 0;
        int res = Integer.MIN_VALUE;
        for (int i = 0; i < a.length; i++) {
            tmp += a[i];
            res = max(res, tmp);
            tmp = max(tmp, 0);
        }
        return res;
    }

    public static void main(String[] args) {
        int n = nextInt();
        Stack<Integer> speed = new Stack<>();
        nextInt();
        int cur_speed = nextInt();
        int count = 0;
        int ans = 0;
        for (int i = 1; i < n; i++) {
            int type = nextInt();
            switch (type) {
                case 1: {
                    int sp = nextInt();
                    while (!speed.isEmpty() && speed.peek() < sp) {
                        speed.pop();
                        ans++;
                    }
                    cur_speed = sp;
                    break;
                }
                case 2: {
                    ans += count;
                    count = 0;
                    break;
                }
                case 3: {
                    int sp = nextInt();
                    if (cur_speed > sp) {
                        ans++;
                    } else {
                        speed.add(sp);
                    }
                    break;
                }
                case 4: {
                    count = 0;
                    break;
                }
                case 5: {
                    speed = new Stack<>();
                    break;
                }
                case 6: {
                    count++;
                }
            }
        }
        System.out.println(ans);
    }
}

