#include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<n; i++)
#define REP(i,x,n) for (int i=x; i<n; i++)
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using T = tuple<int,int,int>;
using P = pair<int,int>;

const ll SEG_LEN = (1 << 20);

ll seg[SEG_LEN * 2];

void update(ll ind, ll val){
    ind += SEG_LEN;
    seg[ind] ^= val;
    while (1){
        //cout << seg[ind] << " ";
        ind /= 2;
        if (ind == 0) break;
        seg[ind] = seg[ind * 2] ^ seg[ind * 2 + 1];
    }
    // cout << endl;
}

ll XOR(int ql, int qr, int sl = 0, int sr = 1 << 20, int pos = 1){
    //被らない
    if (qr <= sl || sr <= ql) return 0;
    //完全に包まれる
    if (ql <= sl && sr <= qr) return seg[pos];
    //部分的に被る
    int sm = (sl + sr) / 2;
    ll left = XOR(ql, qr, sl, sm, pos * 2);
    ll right = XOR(ql, qr, sm, sr, pos * 2 + 1);
    return left ^ right;
}

int main(){
    int n, q;
    cin >> n >> q;
    rep(i,n) {
        ll ai;
        cin >> ai;
        update(i, ai);
    }

    // for (auto ele : seg){
    //     cout << ele << endl;
    // }

    rep(i,q){
        int ti, xi, yi;
        cin >> ti >> xi >> yi;
        if (ti == 1) update(xi-1, yi);
        if (ti == 2) {
            ll ans = XOR(xi-1, yi);
            cout << ans << endl;
        }
    }

    // for (auto ele : seg){
    //     cout << ele << endl;
    // }
}

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

// #pragma GCC target ("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimization ("unroll-loops")
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC target("fpmath=387") //extra precision    

#define debug_input cout<<"input"<<endl;freopen("input.txt","r",stdin);
#define debug_output cout<<"output"<<endl;freopen("output.txt","w",stdout);
#define debug debug_input;debug_output;

typedef double db;
typedef string str;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef pair<double,double> pd;

#define F first
#define S second
#define endl '\n'
#define ALL(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for(int i=a;i<(int)b;i++)
#define FORN(i,a,b) for(int i=a;i<=(int)b;i++)
#define FORB(i,a,b) for(int i=a;i>=(int)b;i--)
#define REP(i,x) FOR(i,0,x)
#define MEM(arr, x) memset(arr, (x), sizeof(arr))

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<str> vs;
typedef vector<pi> vii;
typedef vector<pl> vll;

const int MOD = 1e9+7; 
const ll INF = 1e18;
const ld PI = acos((ld)-1);

const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1};
const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};

str x;
int ava(ll base, ll m){
    ll newVal = 0;
    for(int i=0; i< (int)x.size();i++){
        if(newVal > m / base)   
            return 0;
        newVal = newVal * base + (x[i] - '0');
    }
    return newVal <= m;
}
void solve(){
    ll m;
    cin>>x>>m;

    if(x.size() == 1){
        if(ava(10, m))   cout<<1;
        else    cout<<0;
        cout<<endl;
        return;
    }

    int maxB = -1;
    for(int i=0; i< (int)x.size();i++)
        maxB = max(maxB, x[i] - '0');

    ll l = maxB;
    ll r = 1LL << 60;
    while(l + 1 < r){
        ll mid = (l + r) / 2;
        if(ava(mid, m))
            l = mid;
        else    r = mid;
    }
    cout<<l - maxB<<endl;
}
int main(){
    ios_base::sync_with_stdio(false);cin.tie(nullptr);
    // cout.tie(nullptr);
    // debug_output;
    // debug;
    
    int t = 1;
    // cin>>t;
    for(int tc=1;tc<=t;tc++){
        // cout<<"Case #"<<tc<<": ";
        solve();
    }
    return 0;
}