#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 10;

struct Node {
    int l, r;
    int max_len, prefix, suffix;
    int tag; // -1 无覆盖 | 0 or 1覆盖
} tr[N << 2];

struct Info {
    int max_len, prefix, suffix, total;
};

void push_up(int u) {
    Node &left = tr[u << 1];
    Node &right = tr[u << 1 | 1];
    tr[u].prefix = left.prefix;
    if (left.prefix == left.r - left.l + 1) {
        tr[u].prefix += right.prefix;
    }
    tr[u].suffix = right.suffix;
    if (right.suffix == right.r - right.l + 1) {
        tr[u].suffix += left.suffix;
    }
    tr[u].max_len = max({left.max_len, right.max_len, left.suffix + right.prefix});
}

void push_down(int u) {
    if (tr[u].tag != -1) {
        int tag = tr[u].tag;
        int lson = u << 1, rson = u << 1 | 1;
        tr[lson].max_len = tr[lson].prefix = tr[lson].suffix = tag ? (tr[lson].r - tr[lson].l + 1) : 0;
        tr[lson].tag = tag;
        tr[rson].max_len = tr[rson].prefix = tr[rson].suffix = tag ? (tr[rson].r - tr[rson].l + 1) : 0;
        tr[rson].tag = tag;
        tr[u].tag = -1;
    }
}

void build(int u, int l, int r, const string &s) {
    tr[u].l = l;
    tr[u].r = r;
    tr[u].tag = -1;
    if (l == r) {
        int val = s[l - 1] - '0';
        tr[u].max_len = tr[u].prefix = tr[u].suffix = val;
        return;
    }
    int mid = (l + r) >> 1;
    build(u << 1, l, mid, s);
    build(u << 1 | 1, mid + 1, r, s);
    push_up(u);
}

void update(int u, int l, int r, int x) {
    if (tr[u].l >= l && tr[u].r <= r) {
        tr[u].max_len = tr[u].prefix = tr[u].suffix = x ? (tr[u].r - tr[u].l + 1) : 0;
        tr[u].tag = x;
        return;
    }
    push_down(u);
    int mid = (tr[u].l + tr[u].r) >> 1;
    if (l <= mid) update(u << 1, l, r, x);
    if (r > mid) update(u << 1 | 1, l, r, x);
    push_up(u);
}

Info query(int u, int ql, int qr) {
    if (tr[u].r < ql || tr[u].l > qr) {
        return {0, 0, 0, 0};
    }
    if (ql <= tr[u].l && tr[u].r <= qr) {
        return {tr[u].max_len, tr[u].prefix, tr[u].suffix, tr[u].r - tr[u].l + 1};
    }
    push_down(u);
    Info left = query(u << 1, ql, qr);
    Info right = query(u << 1 | 1, ql, qr);
    if (left.total == 0) return right;
    if (right.total == 0) return left;
    Info res;
    res.prefix = left.prefix;
    if (left.prefix == left.total) {
        res.prefix += right.prefix;
    }
    res.suffix = right.suffix;
    if (right.suffix == right.total) {
        res.suffix += left.suffix;
    }
    res.max_len = max({left.max_len, right.max_len, left.suffix + right.prefix});
    res.total = left.total + right.total;
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    build(1, 1, n, s);
    while (q--) {
        int op;
        cin >> op;
        if (op == 1) {
            int l, r, x;
            cin >> l >> r >> x;
            update(1, l, r, x);
        } else {
            int l, r;
            cin >> l >> r;
            Info info = query(1, l, r);
            cout << info.max_len << '\n';
        }
    }
    return 0;
}