Appleman has a very big sheet of paper. This sheet has a form of rectangle with dimensions 1 × n. Your task is help Appleman with folding of such a sheet. Actually, you need to perform q queries. Each query will have one of the following types:

  1. Fold the sheet of paper at position pi. After this query the leftmost part of the paper with dimensions 1 × pi must be above the rightmost part of the paper with dimensions 1 × ([current width of sheet] - pi). 
  2. Count what is the total width of the paper pieces, if we will make two described later cuts and consider only the pieces between the cuts. We will make one cut at distance li from the left border of the current sheet of paper and the other at distance ri from the left border of the current sheet of paper. 



Please look at the explanation of the first test example for better understanding of the problem.

Input

The first line contains two integers: n and q (1 ≤ n ≤ 105; 1 ≤ q ≤ 105) — the width of the paper and the number of queries.

Each of the following q lines contains one of the described queries in the following format:

  * "1 pi" (1 ≤ pi < [current width of sheet]) — the first type query. 
  * "2 li ri" (0 ≤ li < ri ≤ [current width of sheet]) — the second type query. 

Output

For each query of the second type, output the answer.

Examples

Input

7 4
1 3
1 2
2 0 1
2 1 2


Output

4
3


Input

10 9
2 2 9
1 1
2 0 1
1 8
2 0 8
1 2
2 1 3
1 4
2 2 4


Output

7
2
10
4
5

Note

The pictures below show the shapes of the paper during the queries of the first example:

<image>

After the first fold operation the sheet has width equal to 4, after the second one the width of the sheet equals to 2.
import java.util.*;
import java.io.*;
import java.text.*;
public class Main{
    //SOLUTION BEGIN
    //Into the Hardware Mode
    void pre() throws Exception{}
    void solve(int TC) throws Exception{
        int n = ni(), q = ni();
        Treap root = null;
        for(int i = 1; i<= n; i++)root = insert(root, i, 1);
        while(q-->0){
            if(ni() == 1)
                root = fold(root, ni());
            else {
                root = sum(root, ni()+1, ni());
                pn(ans);
            }
        }
    }
    void print(Treap root, int d){
        if(root == null)return;
        push(root);
        print(root.le, d+1);
        for(int i = 0; i< d; i++)p(" ");pn(root.cur);
        print(root.ri, d+1);
    }
    HashSet<Long> set = new HashSet<>();
    Random r = new Random();
    class Treap{
        long prio, cur, sum;
        int sz;
        boolean rev;
        Treap le, ri;
        public Treap(long x){
            do prio = r.nextLong();
            while (set.contains(prio));
            set.add(prio);
            sz = 1;
            cur = x;sum = x;
            rev = false;
        }
        private Treap(){}
        public Treap copy(){
            Treap node = new Treap();
            node.rev = rev;
            node.sum = sum;
            node.cur = cur;
            node.prio = prio;
            node.le = le;
            node.ri = ri;
            node.sz = sz;
            return node;
        }
    }
    Treap copy(Treap node){
        if(node == null)return null;
        return node.copy();
    }
    int sz(Treap node){return node == null?0:node.sz;}
    long sum(Treap node){return node == null?0:node.sum;}
    void push(Treap node){
        if(node == null || !node.rev)return;
        node.rev = false;
        Treap tmp = copy(node.le);
        node.le = copy(node.ri);
        node.ri = tmp;
        if(node.le != null)node.le.rev ^= true;
        if(node.ri != null)node.ri.rev ^= true;
    }
    void update(Treap node){
        if(node == null)return;
        node.sz = 1+sz(node.le)+sz(node.ri);
        node.sum = node.cur+sum(node.le)+sum(node.ri);
    }
    Treap[] split(Treap node, int p, int add){
        if(node == null)return new Treap[]{null, null};
        push(node);
        if(p <= add+sz(node.le)){
            Treap[] sp = split(node.le, p, add);
            node.le = sp[1];
            update(node);
            sp[1] = node;
            return sp;
        }else {
            Treap[] sp = split(node.ri, p, add+1+sz(node.le));
            node.ri = sp[0];
            update(node);
            sp[0] = node;
            return sp;
        }
    }
    Treap merge(Treap le, Treap ri){
        if(le == null)return ri;
        if(ri == null)return le;
        push(le);
        push(ri);
        if(le.prio > ri.prio){
            le.ri = merge(le.ri, ri);
            update(le);
            return le;
        }else {
            ri.le = merge(le, ri.le);
            update(ri);
            return ri;
        }
    }
    Treap insert(Treap root, int p, int x){
        Treap[] sp = split(root, p-1, 0);
        return merge(merge(sp[0], new Treap(x)), sp[1]);
    }
    long[] tmpArray;int cnt = 0;
    void fill(Treap node){
        if(node == null)return;
        push(node);
        fill(node.le);
        tmpArray[cnt++] = node.cur;
        fill(node.ri);
    }
    Treap increase(Treap root, int pos, int add, long val){
//        if(root == null)return null;
        push(root);
        if(pos<= add+sz(root.le))root.le = increase(root.le, pos, add, val);
        else if(pos > add+1+sz(root.le))root.ri = increase(root.ri, pos, add+1+sz(root.le), val);
        else root.cur += val;
        update(root);
        return root;
    }
    Treap fold(Treap root, int p){
        Treap[] sp = split(root, p, 0);
        if(sz(sp[0]) > sz(sp[1])){
            tmpArray = new long[sz(sp[1])];cnt = 0;
            fill(sp[1]);
            int size = sz(sp[0]);
            for(int i = 0; i< cnt; i++)sp[0] = increase(sp[0], size--, 0, tmpArray[i]);
            sp[0].rev ^= true;
            return sp[0];
        }else{
            tmpArray = new long[sz(sp[0])];cnt = 0;
            fill(sp[0]);
            for(int i = 0; i< cnt; i++)sp[1] = increase(sp[1], i+1, 0, tmpArray[cnt-i-1]);
            return sp[1];
        }
    }
    long ans;
    Treap sum(Treap root, int l, int r){
        Treap[] sp = split(root, r, 0);
        Treap[] sp2 = split(sp[0], l-1, 0);
        ans = sum(sp2[1]);
        return merge(merge(sp2[0], sp2[1]), sp[1]);
    }
    //SOLUTION END
    void hold(boolean b)throws Exception{if(!b)throw new Exception("Hold right there, Sparky!");}
    void exit(boolean b){if(!b)System.exit(0);}
    //    long IINF = (long)1e15;
    final int INF = (int)1e9+2, MX = (int)2e6+5;
    DecimalFormat df = new DecimalFormat("0.00000000000");
    double PI = 3.141592653589793238462643383279502884197169399, eps = 1e-8;
    static boolean multipleTC = false, memory = false, fileIO = false;
    FastReader in;PrintWriter out;
    void run() throws Exception{
        long ct = System.currentTimeMillis();
        if (fileIO) {
            in = new FastReader("");
            out = new PrintWriter("");
        } else {
            in = new FastReader();
            out = new PrintWriter(System.out);
        }
        //Solution Credits: Taranpreet Singh
        int T = (multipleTC) ? ni() : 1;
        pre();
        for (int t = 1; t <= T; t++) solve(t);
        out.flush();
        out.close();
        System.err.println(System.currentTimeMillis() - ct);
    }
    public static void main(String[] args) throws Exception{
        if(memory)new Thread(null, new Runnable() {public void run(){try{new Main().run();}catch(Exception e){e.printStackTrace();}}}, "1", 1 << 28).start();
        else new Main().run();
    }
    int[][] make(int n, int[] from, int[] to, int e, boolean f){
        int[][] g = new int[n][];int[]cnt = new int[n];
        for(int i = 0; i< e; i++){
            cnt[from[i]]++;if(f)cnt[to[i]]++;
        }
        for(int i = 0; i< n; i++)g[i] = new int[cnt[i]];
        for(int i = 0; i< e; i++){
            g[from[i]][--cnt[from[i]]] = to[i];
            if(f)g[to[i]][--cnt[to[i]]] = from[i];
        }
        return g;
    }
    int[][][] makeS(int n, int[] from, int[] to, boolean f){
        int[][][] g = new int[n][][];int[]cnt = new int[n];
        for(int i:from)cnt[i]++;if(f)for(int i:to)cnt[i]++;
        for(int i = 0; i< n; i++)g[i] = new int[cnt[i]][];
        for(int i = 0; i< from.length; i++){
            g[from[i]][--cnt[from[i]]] = new int[]{to[i], i};
            if(f)g[to[i]][--cnt[to[i]]] = new int[]{from[i], i};
        }
        return g;
    }
    int find(int[] set, int u){return set[u] = (set[u] == u?u:find(set, set[u]));}
    int digit(long s){int ans = 0;while(s>0){s/=10;ans++;}return ans;}
    long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}
    int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}
    int bit(long n){return (n==0)?0:(1+bit(n&(n-1)));}
    void p(Object o){out.print(o);}
    void pn(Object o){out.println(o);}
    void pni(Object o){out.println(o);out.flush();}
    String n()throws Exception{return in.next();}
    String nln()throws Exception{return in.nextLine();}
    int ni()throws Exception{return Integer.parseInt(in.next());}
    long nl()throws Exception{return Long.parseLong(in.next());}
    double nd()throws Exception{return Double.parseDouble(in.next());}

    class FastReader{
        BufferedReader br;
        StringTokenizer st;
        public FastReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastReader(String s) throws Exception{
            br = new BufferedReader(new FileReader(s));
        }

        String next() throws Exception{
            while (st == null || !st.hasMoreElements()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (IOException  e){
                    throw new Exception(e.toString());
                }
            }
            return st.nextToken();
        }

        String nextLine() throws Exception{
            String str;
            try{
                str = br.readLine();
            }catch (IOException e){
                throw new Exception(e.toString());
            }
            return str;
        }
    }
}