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.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class CodeC {
  public static class Fenwick
  {
      long[] fenwickTree;
      int tam;
      
      public Fenwick(int t)
      {
          fenwickTree = new long[t];
          tam = t;
      }
      
      long query(int a, int b) 
      {
          if (a == 0)
          {
              long sum = 0;
              for (; b >= 0; b = (b & (b + 1)) - 1)
                sum += fenwickTree[b];
              return sum;
          } 
          else 
          {
              return (query(0, b) - query(0, a - 1));
          }
      }
  
      void increase(int k, long inc)
      {
          for (; k < tam; k |= k + 1)
              fenwickTree[k] += inc;
      }
      
      void increaseRange(int a, int b, long val)
      {
          increase(a, val);
          increase(b + 1, -val);
      }
      
      long queryRangePoint(int a)
      {
          return query(0, a);
      }
  }

  static class Array {
    boolean inverted;
    int[] array;
    Fenwick fenwick;
    int a;
    int b;

    public Array(int n) {
      array = new int[n];
      a = 0;
      b = n - 1;
      inverted = false;
      fenwick = new Fenwick(n + 1);
    }

    int getIndex(int i) {
      if (inverted) {
        return b - i;
      } else {
        return a + i;
      }
    }

    int get(int i) {
      return array[getIndex(i)];
    }

    void cutFirst(int n) {
      if (inverted) {
        b -= n;
      } else {
        a += n;
      }
    }

    void invert() {
      inverted = !inverted;
    }

    void add(int i, int value) {
      array[getIndex(i)] += value;
      fenwick.increase(getIndex(i), value);
    }

    int getSum(int i, int j) {
      int indexI = getIndex(i);
      int indexJ = getIndex(j);
      if (indexI > indexJ) {
        int tmp = indexI;
        indexI = indexJ;
        indexJ = tmp;
      }
      return (int) fenwick.query(indexI, indexJ);
    }

    int length() {
      return (b - a) + 1;
    }
  }

  public static void main(String[] args) {
    Scanner sc = new SuperScanner();
    int n = sc.nextInt();
    int q = sc.nextInt();
    Array array = new Array(n);
    for (int i = 0; i < n; i++) {
      array.add(i, 1);
    }
    for (int i = 0; i < q; i++) {
      int type = sc.nextInt();
      if (type == 1) {
        int p = sc.nextInt();
        int arrayLength = array.length();
        if (p > array.length() / 2) {
          array.invert();
          p = arrayLength - p;
        }
        int last = p + p - 1;
        for (int startA = 0; startA < p; startA++) {
          array.add(last--, array.get(startA));
        }
        array.cutFirst(p);
      } else {
        int left = sc.nextInt();
        int right = sc.nextInt() - 1;
        System.out.println(array.getSum(left, right));
      }
    }
  }

  static class SuperScanner extends Scanner {
    private InputStream stream;
    private byte[] buf = new byte[8096];
    private int curChar;
    private int numChars;

    public SuperScanner() {
        this.stream = System.in;
    }

    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }
    
    public static boolean isWhitespace(int c) {
      return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }
    
    private final StringBuilder sb = new StringBuilder();
    
    @Override
    public String next() {
      int c = read();
      while (isWhitespace(c)) {
          if (c == -1) {
            return null;
          }
          c = read();
      }
      sb.setLength(0);
      do {
          sb.append((char) c);
          c = read();
      } while (!isWhitespace(c));
      return sb.toString();
    }

    @Override
    public int nextInt() {
        int c = read();
        while (isWhitespace(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res = (res << 3) + (res << 1);
            res += c - '0';
            c = read();
        } while (!isWhitespace(c));
        return res * sgn;
    }

    @Override
    public long nextLong() {
        int c = read();
        while (isWhitespace(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        long res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res = (res << 3) + (res << 1);
            res += c - '0';
            c = read();
        } while (!isWhitespace(c));
        return res * sgn;
    }
  }
  
  static class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");

    public String nextLine() {
      try {
        return br.readLine();
      } catch (Exception e) {
        throw (new RuntimeException());
      }
    }

    public int nextIntOrQuit() {
      Integer n = nextInteger();
      if (n == null) {
        System.exit(0);
      }
      return n.intValue();
    }

    public String next() {
      while (!st.hasMoreTokens()) {
        String l = nextLine();
        if (l == null)
          return null;
        st = new StringTokenizer(l);
      }
      return st.nextToken();
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
      int[] res = new int[n];
      for (int i = 0; i < res.length; i++)
        res[i] = nextInt();
      return res;
    }

    public long[] nextLongArray(int n) {
      long[] res = new long[n];
      for (int i = 0; i < res.length; i++)
        res[i] = nextLong();
      return res;
    }

    public double[] nextDoubleArray(int n) {
      double[] res = new double[n];
      for (int i = 0; i < res.length; i++)
        res[i] = nextDouble();
      return res;
    }

    public void sortIntArray(int[] array) {
      Integer[] vals = new Integer[array.length];
      for (int i = 0; i < array.length; i++)
        vals[i] = array[i];
      Arrays.sort(vals);
      for (int i = 0; i < array.length; i++)
        array[i] = vals[i];
    }

    public void sortLongArray(long[] array) {
      Long[] vals = new Long[array.length];
      for (int i = 0; i < array.length; i++)
        vals[i] = array[i];
      Arrays.sort(vals);
      for (int i = 0; i < array.length; i++)
        array[i] = vals[i];
    }

    public void sortDoubleArray(double[] array) {
      Double[] vals = new Double[array.length];
      for (int i = 0; i < array.length; i++)
        vals[i] = array[i];
      Arrays.sort(vals);
      for (int i = 0; i < array.length; i++)
        array[i] = vals[i];
    }

    public String[] nextStringArray(int n) {
      String[] vals = new String[n];
      for (int i = 0; i < n; i++)
        vals[i] = next();
      return vals;
    }

    public Integer nextInteger() {
      String s = next();
      if (s == null)
        return null;
      return Integer.parseInt(s);
    }

    public int[][] nextIntMatrix(int n, int m) {
      int[][] ans = new int[n][];
      for (int i = 0; i < n; i++)
        ans[i] = nextIntArray(m);
      return ans;
    }

    public char[][] nextGrid(int r) {
      char[][] grid = new char[r][];
      for (int i = 0; i < r; i++)
        grid[i] = next().toCharArray();
      return grid;
    }

    public static <T> T fill(T arreglo, int val) {
      if (arreglo instanceof Object[]) {
        Object[] a = (Object[]) arreglo;
        for (Object x : a)
          fill(x, val);
      } else if (arreglo instanceof int[])
        Arrays.fill((int[]) arreglo, val);
      else if (arreglo instanceof double[])
        Arrays.fill((double[]) arreglo, val);
      else if (arreglo instanceof long[])
        Arrays.fill((long[]) arreglo, val);
      return arreglo;
    }

    public <T> T[] nextObjectArray(Class<T> clazz, int size) {
      @SuppressWarnings("unchecked")
      T[] result = (T[]) java.lang.reflect.Array.newInstance(clazz, size);
      for (int c = 0; c < 3; c++) {
        Constructor<T> constructor;
        try {
          if (c == 0)
            constructor = clazz.getDeclaredConstructor(Scanner.class,
                Integer.TYPE);
          else if (c == 1)
            constructor = clazz.getDeclaredConstructor(Scanner.class);
          else
            constructor = clazz.getDeclaredConstructor();
        } catch (Exception e) {
          continue;
        }
        try {
          for (int i = 0; i < result.length; i++) {
            if (c == 0)
              result[i] = constructor.newInstance(this, i);
            else if (c == 1)
              result[i] = constructor.newInstance(this);
            else
              result[i] = constructor.newInstance();
          }
        } catch (Exception e) {
          throw new RuntimeException(e);
        }
        return result;
      }
      throw new RuntimeException("Constructor not found");
    }

    public void printLine(int... vals) {
      if (vals.length == 0)
        System.out.println();
      else {
        System.out.print(vals[0]);
        for (int i = 1; i < vals.length; i++)
          System.out.print(" ".concat(String.valueOf(vals[i])));
        System.out.println();
      }
    }

    public void printLine(long... vals) {
      if (vals.length == 0)
        System.out.println();
      else {
        System.out.print(vals[0]);
        for (int i = 1; i < vals.length; i++)
          System.out.print(" ".concat(String.valueOf(vals[i])));
        System.out.println();
      }
    }

    public void printLine(double... vals) {
      if (vals.length == 0)
        System.out.println();
      else {
        System.out.print(vals[0]);
        for (int i = 1; i < vals.length; i++)
          System.out.print(" ".concat(String.valueOf(vals[i])));
        System.out.println();
      }
    }

    public void printLine(int prec, double... vals) {
      if (vals.length == 0)
        System.out.println();
      else {
        System.out.printf("%." + prec + "f", vals[0]);
        for (int i = 1; i < vals.length; i++)
          System.out.printf(" %." + prec + "f", vals[i]);
        System.out.println();
      }
    }

    public Collection<Integer> wrap(int[] as) {
      ArrayList<Integer> ans = new ArrayList<Integer>();
      for (int i : as)
        ans.add(i);
      return ans;
    }

    public int[] unwrap(Collection<Integer> collection) {
      int[] vals = new int[collection.size()];
      int index = 0;
      for (int i : collection)
        vals[index++] = i;
      return vals;
    }
  }
}