////**********************AUTHOR:stranger1O**********************////

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

#define Input(v,n)        vector<int>v(n);for(long i=0;i<n;i++){cin>>v[i];}                
#define check(v,n)        for(int i=0;i<n;i++){cout<<v[i]<<" ";}cout<<endl;
#define sort(v)           sort(v.begin(),v.end());
#define int               long long int
#define fr(i,n)           for(int i=0;i<n;i++)
#define frr(i,s,e)        for(int i=s;i<=e;i++)
#define endl              "\n"



int n,q;

void solve(){
  
     
  cin>>n>>q;
  int arr[n];
  map<int,int>mp;


  fr(i,n){
    cin>>arr[i];
    mp[arr[i]]++;
  }

  fr(i,q){
    int t,x;cin>>t>>x;
    if(t==1){
      mp[arr[x-1]]--;
      arr[x-1]=1-arr[x-1];
      mp[arr[x-1]]++;
     
    }

    else{
      int l=mp.size();
      auto it=mp.end();
      it--;
      int temp=0;
      fr(j,l){
           temp+=it->second;
           if(temp>=x){
             cout<<it->first<<endl;
             break;
           } 
           it--;
      }
    }
  } 


}

int32_t main(){ 
    
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
  #endif


    // int tc;cin>>tc;
    // while(tc--) 
    solve();
        
    
    
    return 0;
}