#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
int t, n, a[N];
pair<int, int> ok(int x){
map<int, int> fq;
int mx = 0;
multiset<int> s;
auto add = [&](int c){
if(s.find(fq[c]) != s.end()) s.erase(s.find(fq[c]));
fq[c]++;
s.insert(fq[c]);
};
auto rem = [&](int c){
if(s.find(fq[c]) != s.end()) s.erase(s.find(fq[c]));
fq[c]--;
s.insert(fq[c]);
};
for(int i = x + 1;i<=n;i++){
add(a[i]);
}
pair<int, int> cc = {-1, -1};
if(*s.rend() == 1) cc = {1, x};
for(int i = x + 1;i<=n;i++){
rem(a[i]);
add(a[i - x]);
if(*s.rbegin() == 1) cc = {i - x + 1, i};
}
return cc;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> t >> n;
for(int i = 1;i<=n;i++){
cin >> a[i];
}
int l = 1, r = n - 1;
pair<int, int> res;
while(l <= r){
int md = (l + r) / 2;
if(ok(md).first != -1){
res = ok(md);
r = md - 1;
}else{
l = md + 1;
}
}
cout << res.first - 1 << ' ' << res.second - 1;
}