#include using namespace std; //repetition #define FOR(i,a,b) for(ll i=(a);i<(b);++i) #define rep(i, n) for(ll i = 0; i < (ll)(n); i++) //container util #define all(x) (x).begin(),(x).end() //typedef typedef long long ll; typedef vector VI; typedef vector VVI; typedef vector VLL; typedef vector VVLL; typedef vector VS; typedef pair PII; typedef pair PLL; //const value //const ll MOD = 1e9 + 7; //const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1}; //const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1}; //conversion inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;} inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;} template inline string toString(T x) {ostringstream sout;sout< node; void init(int x){ n = 1; while(n < x) n *= 2; node.resize(n*2-1,PII(INT_MAX,-1)); } void update(int i, int x){ i += n-1; node[i] = PII(x,i-(n-1)); while(i > 0){ i = (i-1)/2; node[i] = min(node[i*2 +1],node[i*2+2]); } } PII getMin(int x, int y, int k=0, int l=0, int r=-1){ if(r < 0) r = n; if(r<=x || l>=y) return PII(INT_MAX,-1); if(x<=l && r<=y) return node[k]; PII vl = getMin(x, y, 2*k+1, l, (l+r)/2); PII vr = getMin(x, y, 2*k+2, (l+r)/2, r); return min(vl,vr); } }; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n,q; cin >> n >> q; segTree t; t.init(n); rep(i,n){ int a; cin >> a; t.update(i,a); } rep(i,q){ int cmd; cin >> cmd; if(cmd == 1){ int y,x; cin >> x >> y; x--,y--; int r = t.node.at(x+n-1).second; int l = t.node.at(y+n-1).second; t.update(x,l); t.update(y,r); }else{ int x,y; cin >> x >> y; x--,y--; cout << t.getMin(x,y+1).second + 1 << endl; } } return 0; }