//pB
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pii pair<int, int>
#define S second
#define F first
const int maxn = 1e6 + 10;
const int inf = 1e9;
int n, p;
vector<int> v[maxn];
struct Seg{
bool node[maxn*4]={};
void pull(int id){
node[id]= node[id*2] & node[id*2+1];
}
int edit(int L, int R, int id, int p, bool v, int d){
if(L == R){
node[id]=v;
return d;
}
int mm=(L+R)/2;
int dep=0;
if(p<=mm) dep = edit(L, mm, id*2, p, v, d+1);
else dep = edit(mm+1, R, id*2+1, p, v, d+1);
pull(id);
if(node[id]) return d;
return dep;
}
}seg;
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin>>p>>n;
if(p==1){
cout<<17<<endl;
for(int i=1; i<n; i++){
int x; cin>>x;
cout<< seg.edit(1, n, 1, x+1, 1, 1) <<endl;
}
}else{
for(int i=1; i<=n; i++){
int x; cin>>x;
v[x].push_back(i);
}
if(v[1].size()){
cout<<v[1][0]-1<<" "<<v[1][0]-1<<endl;
return 0;
}
int L=1, R=n;
for(int i=2; i<=17; i++){
auto a = lower_bound(v[i].begin(), v[i].end(), L);
auto b = upper_bound(v[i].begin(), v[i].end(), R);
if(b-a == 2){
cout<<*a - 1<<" "<<*prev(b) - 1<<endl;
return 0;
}else{ // if(b-a == 1)
int mm=(L+R)/2;
if(*a>mm) R=mm;
else L=mm+1;
}
if(L==R){
cout<<L - 1<<" "<<R - 1<<endl;
return 0;
}
}
cout<<L - 1<<" "<<R - 1<<endl;
}
}