#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
#define Shahriyor ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define vi vector<int>
#define vvi vector<vi>
#define vvvi vector<vvi>
#define vc vector<char>
#define vs vector<string>
#define vp vector<pair<int,int>>
#define vvp vector<vector<pair<int,int>>>
#define all(x) (x).begin(), (x).end()
#define allr(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
#define endl '\n'
#define len(a) (int)(a).length()
#define inf 4e18
#define print(x) { cout << x << endl; return; }
void Solve();
int mod = 1e9+7;
int LOG = 20;
vi dx = {-1, 1, 0, 0, 1, -1, 1, -1};
vi dy = {0, 0, 1, -1, 1, -1, -1, 1};
ostream& operator<<(ostream& out, vi& a) {
for(int i=0;i<sz(a);i++) out << a[i] << ' ';
return out;
}
istream& operator>>(istream& in, vi& a) {
for(int i=0;i<sz(a);i++) in >> a[i];
return in;
}
int sum(vi& l) {return accumulate(all(l),(int)0);}
int binpow(int a, int b){
int res = 1;
while(b){
if(b & 1) res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
signed main(){
clock_t start = clock();
Shahriyor;
int t = 1;
// cin >> t;
while(t--) Solve();
// cerr << "Time: " << double(clock() - start) / double(CLOCKS_PER_SEC) * 1000 << " ms\n";
}
int ans=-1,a,b;
int t,n;
void res(vi& l,int is_rev){
int left=inf,right=-inf;
map<int,int> min_mp;
map<int,int> max_mp;
vi last_occ(t+5,0);
vi cnt(t+5,0);
for(int i=0;i<n;i++){
cnt[l[i]]++;
if(cnt[l[i]]==2) min_mp[l[i]]=i;
if(cnt[l[i]]>1) max_mp[l[i]]=last_occ[l[i]];
last_occ[l[i]]=i;
}
for(int i=0;i<n;i++){
if(i==left) break;
if(min_mp.count(l[i])) left=min(left,min_mp[l[i]]);
right=max(right,last_occ[l[i]]);
}
for(int i=n-1;~i;i--){
if(i==right) break;
if(max_mp.count(l[i])) right=max(right,max_mp[l[i]]);
}
set<int> st;
for(int i=0;i<n;i++){
if(left<=i && i<=right) continue;
st.insert(l[i]);
}
if(is_rev){
int new_right=n-left-1;
int new_left=n-right-1;
left=new_left,right=new_right;
}
if(sz(st)>ans) ans=sz(st),a=left,b=right;
}
void Solve(){
cin>>t>>n;
vi l(n); cin>>l;
res(l,0);
reverse(all(l));
res(l,1);
cout << a << " " << b << endl;
}