#include using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define all(x) (x).begin(),(x).end() const int mod = 1000000007; const long long INF = 1LL << 60; using ll = long long; int main() { int N; cin >> N; int ans=0; vector a(N); rep(i,N){ cin >> a[i]; if(a[i]==N){ ans=N*(N+1)/2-(i+1); } } cout << ans << endl; }