from collections import defaultdict from random import randint pool = defaultdict(lambda: randint(1, (1 << 61) - 1)) curHash = 0 history = {0: 0} n, q = map(int, input().split()) for i in range(q): op, *args = input().split() if op == "?": print(history.get(curHash, -1)) else: left, rigth, add = map(int, args) curHash += (pool[rigth] - pool[left]) * add history.setdefault(curHash, i + 1)