//EGOI 2025 Gift Boxes
//https://qoj.ac/contest/2343/problem/13165
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
const ll MAXN = 5e6;
vll team[MAXN], freq(MAXN,0);
int main(){
ll t, n, l=1e18, r=-1e18, ansL=-1e18, ansR=1e18;
cin >> t >> n;
vll A(n);
for(int i=0; i<n; i++) cin >> A[i], team[A[i]].push_back(i);
for(int i=0; i<t; i++) if(team[i].size()>=3){
l=min(l,team[i][1]); r=max(r,team[i][team[i].size()-2]);
}
auto solve=[&](ll a,ll b){
ll x=-1, y=n-1;
while(y>b && freq[A[y]]==0) freq[A[y]]++, y--;
y++; ansL=x+1; ansR=y-1;
while(x<a){
if(freq[A[x]]==1){
while(y<n && A[y]!=A[x]) freq[A[y]]--, y++;
if(y==n) return;
freq[A[y]]--; y++;
}
freq[A[x]]++;
if((y-1)-(x+1)<ansR-ansL) ansL=x+1, ansR=y-1;
x++;
}
};
if(l!=1e18 && r!=-1e18) solve(l,r);
else solve(n,-1);
cout << ansL << " " << ansR << "\n";
return 0;
}