import random N, Q = map(int, input().split()) MOD = (1 << 61) - 1 BASE = random.randrange(2, MOD) cur = 0 d = {0: 0} for i in range(1, Q + 1): query = input().split() if query[0] == '!': L, R, K = map(int, query[1:]) cur += K * pow(BASE, L, MOD) cur -= K * pow(BASE, R, MOD) cur %= MOD if cur not in d: d[cur] = i else: print(d[cur])