#include using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define all(c) begin(c), end(c) #define dump(x) cerr << __LINE__ << ":\t" #x " = " << (x) << endl int s[1000010]; map first; int main(){ int n, q; cin >> n >> q; s[0] = 1; for(int i = 0; i < n; ++i) s[i+1] = s[i] * 10007; ll cur = 0; for(int i = 0; i < q; ++i){ char c; cin >> c; if(c == '?'){ cout << first[cur] << '\n'; } else { int l, r; ll k; cin >> l >> r >> k; cur += (s[r] - s[l]) * k; } if(!first.count(cur)) first[cur] = i + 1; } }