#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve(){
int t,n; cin>>t>>n;
vector<int>v(n),last(t,-1);
for(int &x: v) cin>>x;
for(int i=n-1;i>=0;i--){
if(last[v[i]]==-1) last[v[i]]=i;
}
unordered_set<int>st;
int l=-1;
for(int i=0;i<n;i++){
if(st.find(v[i])!=st.end()){
if(l==-1) l=i;
}
else st.insert(v[i]);
}
int r=-1;
st.clear();
for(int i=n-1;i>=0;i--){
if(st.find(v[i])!=st.end()){
if(r==-1) r=i;
}
else st.insert(v[i]);
}
int ans=0,lastr=r;
int rans,lans;
//cout<<l<<" "<<r<<"\n";
for(int i=0;i<l;i++){
if(last[v[i]]>lastr) lastr=last[v[i]];
int tam=i+n-lastr;
if(ans<tam){
ans=tam;
lans=i+1;
rans=lastr;
}
//cout<<ans<<" "<<lastr<<"\n";
}
int maxi=max((n-r-1),l);
if(ans<(maxi)){
if(l>(n-r-1)) cout<<l<<" "<<n-1;
else cout<<0<<" "<<r;
}
else cout<<lans<<" "<<rans<<"\n";
}
int main(){
ios::sync_with_stdio(0);
cout.tie(0);
cin.tie(0);
solve();
return 0;
}