#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n, ans = 0;
cin >> n;
vector<int> a(n, 0), srt;
for(int i = 0; i < n; ++i){
cin >> a[i];
}
map<int, int> mp;
set<int> st;
vector<int> dp(n + 5, 0);
for(int z = 0; z < n; ++z){
st.insert(a[z]);
mp[a[z]] += 1;
map<int, int> cur, fc;
int small = -1;
for(auto it : st){
cur[it] = small;
small = it;
}
dp[z] = 1;
fc[a[z]] += 1;
for(int j = z - 1; j >= 0; --j){
if(a[j] != a[j + 1] && (fc[a[j + 1]] != mp[a[j + 1]] && a[j + 1] != a[z])){
dp[z] = dp[j] + 1;
break;
}
if(a[j] != a[j + 1] && cur[a[j + 1]] != a[j]){
dp[z] = dp[j] + 1;
break;
}
fc[a[j]] += 1;
}
}
cout << dp[n - 1] << "\n";
return 0;
}