import sys

def main ():
    n, qc = map(int, sys.stdin.readline().strip().split())

    arr = list(range(n + 1))

    for i in range(qc):
        tokens = list(map(int, sys.stdin.readline().strip().split()))
        typ = tokens[0]

        if typ == 1:
            l = tokens[1]
            r = tokens[2] + 1
            arr[l:r] = reversed(arr[l:r])
        elif typ == 2:
            x = tokens[1]
            sys.stdout.write(str(arr[x]))
            sys.stdout.write("\n")
        else:
            y = tokens[1]
            sys.stdout.write(str(arr.index(y)))
            sys.stdout.write("\n")

if __name__ == "__main__":
    main()
