#include<bits/stdc++.h>
using namespace std;
const int MAXN = 500010;
vector<pair<int,int>> seg(4*MAXN);
vector<int> wow(4*MAXN);
vector<int> pr(MAXN);
void build(int l, int r, int x) {
if(l == r) {
seg[x] = {pr[l],l};
return;
}
int mid = (l+r)/2;
build(l,mid,x*2);
build(mid+1,r,x*2+1);
seg[x] = min(seg[x*2],seg[x*2+1]);
}
void upd(int l, int r, int ql, int qr, int x, int c) {
if(l >= ql && r <= qr) {
wow[x]+=c;
seg[x] = {seg[x].first+c,seg[x].second};
return;
}
if(r < ql || l > qr) {
return;
}
int mid = (l+r)/2;
upd(l,mid,ql,qr,x*2,c);
upd(mid+1,r,ql,qr,x*2+1,c);
seg[x] = min(seg[x*2],seg[x*2+1]);
seg[x] = {seg[x].first+wow[x],seg[x].second};
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,q,a,b;
cin >> n >> q;
vector<int> haha(n+1);
for(int i = 1; i <= n; i++) {
cin >> a;
a--;
haha[i] = a;
pr[i] = pr[i-1]+a;
}
build(1,n,1);
if(pr[n] == -1) {
cout << 1 << " " << seg[1].second%n << "\n";
}
else {
cout << 0 << " " << 0 << "\n";
}
for(int i = 0; i < q; i++) {
cin >> a >> b;
a++;
b++;
upd(1,n,a,n,1,-haha[a]);
upd(1,n,b,n,1,-haha[b]);
upd(1,n,a,n,1,haha[b]);
upd(1,n,b,n,1,haha[a]);
swap(haha[a],haha[b]);
if(pr[n] == -1) {
cout << 1 << " " << seg[1].second%n << "\n";
}
else {
cout << 0 << " " << 0 << "\n";
}
}
return 0;
}