/* Problem URL: https://codeforces.com/edu/course/2/lesson/5/4/practice/contest/280801/problem/F */

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

template <class T, class comp = less<>>
using ordered_set = tree<T, null_type , comp , rb_tree_tag , tree_order_statistics_node_update>;

#define V vector

#define rmin(a, b) a = min(a, b)
#define rmax(a, b) a = max(a, b)

#define rep(i, lim) for (int i = 0; i < (lim); i++)
#define nrep(i, s, lim) for (int i = s; i < (lim); i++)

#define repv(i, v) for (auto &i : (v))
#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; }
#define sortv(v) sort(v.begin(), v.end())
#define all(v) (v).begin(), (v).end()

using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vvvvi = vector<vvvi>;

using ll = long long;

using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vvvvl = vector<vvvl>;

template<class v>
auto operator<<(ostream &os, const vector<v> &vec)->ostream& {
    os << vec[0];
    for (size_t i = 1; i < vec.size(); i++) {
        os << ' ' << vec[i];
    }
    os << '\n';
    return os;
}

template<class v>
auto operator>>(istream &is, vector<v> &vec)->istream& {
    for (auto &i : vec) {
        is >> i;
    }
    return is;
}

template<class v>
auto operator<<(ostream &os, const vector<vector<v>> &vec)->ostream& {
    for (auto &i : vec) {
        os << i[0];
        for (size_t j = 1; j < i.size(); j++) {
            os << ' ' << i[j];
        }
        os << '\n';
    }
    return os;
}

template<class v>
auto operator>>(istream  &is, vector<vector<v>> &vec)->istream& {
    for (auto &i : vec) {
        for (auto &j : i) {
            is >> j;
        }
    }
    return is;
}

class segtree_arithmethic {
    struct node {
        int val;
        int left;
        int right;
    };

    struct lazynode {
        int c;
        int x;
        int xi;
        bool cupd;
        bool xupd;
    };

    V<node> seg;
    V<lazynode> lazy;
    int n;

    int newnode() {
        lazy.emplace_back(0LL, 0LL, 0LL, false, false);
        seg.emplace_back(0LL, -1, -1);

        return seg.size() - 1;
    }

    void createchildren(int i) {
        if (seg[i].left == -1) {
            seg[i].left = newnode();
        }

        if (seg[i].right == -1) {
            seg[i].right = newnode();
        }
    }

    void propagatear(int i, int l, int r) {
        if (!lazy[i].xupd) {
            return;
        }

        seg[i].val = lazy[i].xi + lazy[i].x * (r - l);

        if (l != r) {
            createchildren(i);

            int left = seg[i].left;
            int right = seg[i].right;

            int mid = (l + r) >> 1;

            lazy[left].x = lazy[i].x;
            lazy[left].c = 0;
            lazy[left].xi = lazy[i].xi;
            lazy[left].cupd = false;
            lazy[left].xupd = true;

            lazy[right].x = lazy[i].x;
            lazy[right].c = 0;
            lazy[right].xi = lazy[i].xi + lazy[i].x * (mid - l + 1);
            lazy[right].cupd = false;
            lazy[right].xupd = true;
        }

        lazy[i].xupd = false;
    };

    void propagatec(int i, int l, int r) {
        if (!lazy[i].cupd) {
            return;
        }

        seg[i].val += lazy[i].c;

        if (l != r) {
            createchildren(i);

            int left = seg[i].left;
            int right = seg[i].right;

            lazy[left].c += lazy[i].c;
            lazy[left].cupd = true;

            lazy[right].c += lazy[i].c;
            lazy[right].cupd = true;
        }

        lazy[i].cupd = false;
        lazy[i].c = 0;
    }

    void propagate(int i, int l, int r) {
        propagatear(i, l, r);
        propagatec(i, l, r);
    }

    int x;
    int tl, tr;

    void updatearithmethic(int i, int l, int r, int xi) {
        propagate(i, l, r);

        if (l > tr || r < tl) {
            return;
        }

        if (l >= tl && r <= tr) {
            lazy[i].x = x;
            lazy[i].xi = xi;
            lazy[i].xupd = true;
            lazy[i].c = 0;
            lazy[i].cupd = false;
            propagate(i, l, r);
            return;
        }

        int mid = (l + r) >> 1;

        createchildren(i);

        updatearithmethic(seg[i].left, l, mid, xi);
        updatearithmethic(seg[i].right, mid + 1, r, xi + x * (mid - l + 1));

        seg[i].val = max(seg[seg[i].left].val, seg[seg[i].right].val);
    }

    int c;

    void updateconst(int i, int l, int r) {
        propagate(i, l, r);

        if (l > tr || r < tl) {
            return;
        }

        if (l >= tl && r <= tr) {
            lazy[i].c += c;
            lazy[i].cupd = true;
            propagate(i, l, r);
            return;
        }

        int mid = (l + r) >> 1;

        createchildren(i);

        updateconst(seg[i].left, l, mid);
        updateconst(seg[i].right, mid + 1, r);

        seg[i].val = max(seg[seg[i].left].val, seg[seg[i].right].val);
    }

    int h;

    ll query(int i, int l, int r) {
        propagate(i, l, r);

        if (l == r) {
            return seg[i].val > h ? -1 : l;
        }
        
        int mid = (l + r) >> 1;

        createchildren(i);
        propagate(seg[i].left, l, mid);
        propagate(seg[i].right, mid + 1, r);
        
        if (seg[seg[i].left].val > h) {
            return query(seg[i].left, l, mid);
        }
        int res = query(seg[i].right, mid + 1, r);
        return res == -1 ? mid : res;
    }

    public:
    segtree_arithmethic(int n): n(n) {
        seg.emplace_back(0LL, -1, -1);
        lazy.emplace_back();
    }

    void updatearithmethic(int l, int r, ll x) {
        this->x = x;
        tl = l;
        tr = r;
        updatearithmethic(0, 0, n - 1, x * (-l + 1));
    }

    void updateconst(int l, int r, ll c) {
        this->c = c;
        tl = l;
        tr = r;
        updateconst(0, 0, n - 1);
    }

    ll query(int h) {
        this->h = h;
        return query(0, 0, n - 1);
    }
};

class segtree_sum {
    struct node {
        int val;
        int left;
        int right;
    };

    struct lazynode {
        int val;
        bool upd;
    };

    V<node> seg;
    V<lazynode> lazy;
    int n;

    int newnode() {
        seg.emplace_back(0LL, -1, -1);
        lazy.emplace_back(0LL, false);

        return seg.size() - 1;
    }

    void createchildren(int i) {
        if (seg[i].left == -1) {
            seg[i].left = newnode();
        }

        if (seg[i].right == -1) {
            seg[i].right = newnode();
        }
    }

    void propagate(int i, int l, int r) {
        if (!lazy[i].upd) {
            return;
        }

        seg[i].val = lazy[i].val * (r - l + 1);

        if (l != r) {
            createchildren(i);
            lazy[seg[i].left] = lazy[i];
            lazy[seg[i].right] = lazy[i];
        }

        lazy[i].upd = false;
    }

    int tl, tr;
    int v;

    void upd(int i, int l, int r) {
        propagate(i, l, r);

        if (l > tr || r < tl) {
            return;
        }

        if (l >= tl && r <= tr) {
            lazy[i] = {v, true};
            propagate(i, l, r);
            return;
        }

        int mid = (l + r) >> 1;

        createchildren(i);

        upd(seg[i].left, l, mid);
        upd(seg[i].right, mid + 1, r);

        seg[i].val = seg[seg[i].left].val + seg[seg[i].right].val;
    }

    ll query(int i, int l, int r) {
        if (l > tr || r < tl || i == -1) {
            return 0LL;
        }

        propagate(i, l, r);

        if (l >= tl && r <= tr) {
            return seg[i].val;
        }

        int mid = (l + r) >> 1;

        return query(seg[i].left, l, mid) + query(seg[i].right, mid + 1, r);
    }

    public:
    segtree_sum(int n): n(n) {
        seg.emplace_back(0LL, -1, -1);
        lazy.emplace_back(0LL, false);
    }

    void update(int l, int r, int d) {
        tl = l;
        tr = r;
        v = d;
        upd(0, 0, n - 1);
    }

    ll query(int l, int r) {
        tl = l;
        tr = r;
        return query(0, 0, n - 1);
    }
};

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll n;
    cin >> n;

    ll prev = n;

    if (n > 1) {
        n = 1 << (32 - __builtin_clz(n));
    }

    segtree_arithmethic arithmethic(n);
    segtree_sum sum(n);

    char op;
    while (cin >> op, op != 'E') {
        if (op == 'I') {
            int a, b, d;
            cin >> a >> b >> d;

            arithmethic.updateconst(b + 1, n, -sum.query(a, b));
            arithmethic.updatearithmethic(a, b, d);
            arithmethic.updateconst(a, b, sum.query(0, a - 1));
            sum.update(a, b, d);
            arithmethic.updateconst(b + 1, n, sum.query(a, b));

            continue;
        }

        int h;
        cin >> h;

        cout << min(arithmethic.query(h), prev) << '\n';
    }
}
