In one very large and very respectable company there is a cloakroom with a coat hanger. It is represented by n hooks, positioned in a row. The hooks are numbered with positive integers from 1 to n from the left to the right.

The company workers have a very complicated work schedule. At the beginning of a work day all the employees are not there and the coat hanger in the cloakroom is empty. At some moments of time the employees arrive and some of them leave.

When some employee arrives, he hangs his cloak on one of the available hooks. To be of as little discomfort to his colleagues as possible, the hook where the coat will hang, is chosen like this. First the employee chooses the longest segment among available hooks following in a row. If there are several of such segments, then he chooses the one closest to the right. After that the coat is hung on the hook located in the middle of this segment. If the segment has an even number of hooks, then among two central hooks we choose the one closest to the right.

When an employee leaves, he takes his coat. As all the company workers deeply respect each other, no one takes somebody else's coat.

From time to time the director of this respectable company gets bored and he sends his secretary to see how many coats hang on the coat hanger from the i-th to the j-th hook inclusive. And this whim is always to be fulfilled, otherwise the director gets angry and has a mental breakdown.

Not to spend too much time traversing from the director's office to the cloakroom and back again, the secretary asked you to write a program, emulating the company cloakroom's work.

Input

The first line contains two integers n, q (1 ≤ n ≤ 109, 1 ≤ q ≤ 105), which are the number of hooks on the hanger and the number of requests correspondingly. Then follow q lines with requests, sorted according to time. The request of the type "0 i j" (1 ≤ i ≤ j ≤ n) — is the director's request. The input data has at least one director's request. In all other cases the request contains a positive integer not exceeding 109 — an employee identificator. Each odd appearance of the identificator of an employee in the request list is his arrival. Each even one is his leaving. All employees have distinct identificators. When any employee arrives, there is always at least one free hook.

Output

For each director's request in the input data print a single number on a single line — the number of coats hanging on the hooks from the i-th one to the j-th one inclusive.

Examples

Input

9 11
1
2
0 5 8
1
1
3
0 3 8
9
0 6 9
6
0 1 9


Output

2
3
2
5


import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.HashMap;
import java.util.TreeMap;
import java.util.TreeSet;

public class Hanger {
    class Segment implements Comparable<Segment> {
        int left, right, len;
        Segment(int l, int r) {
            left = l;
            right = r;
            len = r-l+ 1;
        }
        public int compareTo(Segment oth) {
            if (len > oth.len)
                return -1;
            if (len==oth.len&&right > oth.right)
                return -1;
            if(left==oth.left&&right==oth.right)
                return 0;
            return 1;
        }
    }

    class IndexTree {
        HashMap<Integer, Integer> mp = new HashMap<Integer, Integer>();
        int N =(1<<30)- 1;
        int lowbit(int k) {
            return (k & -k);
        }
        void inc(int i, int v) {
            while (i <= N) {
                Integer num = mp.get(i);
                if (num == null)
                    num = 0;
                mp.put(i, num + v);
                i += lowbit(i);
            }
        }
        int get(int i) {
            int res = 0;
            while (i > 0) {
                Integer num = mp.get(i);
                if (num == null)
                    num = 0;
                res += num;
                i -= lowbit(i);
            }
            return res;
        }

        int query(int left, int right) {
            return get(right) - get(left - 1);
        }
    }

    IndexTree tree = new IndexTree();
    TreeSet<Segment> segs = new TreeSet<Segment>();
    HashMap<Integer, Integer> arrive = new HashMap<Integer, Integer>();
    HashMap<Integer, Segment> left = new HashMap<Integer, Segment>();
    HashMap<Integer, Segment> right = new HashMap<Integer, Segment>();
    void run() throws IOException {
        int n = nextInt();
        int m = nextInt();
        segs.add(new Segment(1, n));
        for (int i = 0; i < m; i++) {
            int x = nextInt();
            if (x == 0) {
                out.println(tree.query(nextInt(),nextInt()));
                continue;
            }
            if (!arrive.containsKey(x)) {
                Segment seg = segs.pollFirst();
                int ans = seg.left + seg.len / 2;
                arrive.put(x, ans);
                tree.inc(ans, 1);
                left.remove(ans);
                right.remove(ans);
                if (ans != seg.left) {
                    Segment sg = new Segment(seg.left, ans - 1);
                    segs.add(sg);
                    left.put(ans - 1,sg);
                    right.put(seg.left, sg);
                }
                if (ans != seg.right) {
                    Segment sg = new Segment(ans + 1, seg.right);
                    segs.add(sg);
                    left.put(seg.right, sg);
                    right.put(ans + 1, sg);
                }
            } else {
                int tx =x;
                x=arrive.get(x);
                arrive.remove(tx);
                tree.inc(x, -1);
                Segment sl = left.get(x - 1), sr = right.get(x + 1);
                int a = x, b = x;
                if (sl != null) {
                    a = sl.left;
                    segs.remove(sl);
                }
                if (sr != null) {
                    b = sr.right;
                    segs.remove(sr);
                }
                Segment sg = new Segment(a, b);
                segs.add(sg);
                left.put(b,sg);
                right.put(a, sg);
            }   
        }
        out.close();
    }

    StreamTokenizer in = new StreamTokenizer(new BufferedReader(
            new InputStreamReader(System.in)));
    int nextInt() throws IOException {
        in.nextToken();
        return (int) in.nval;
    }
    PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
    public static void main(String[] args) throws IOException {
        new Hanger().run();
    }
}
