#include<stdio.h>
#define MAX 200000

int main() {
	int N;
	int A[MAX];
	int M[MAX + 10] = { 0 };
	long long cnt = 0;
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%d", &A[i]);
	}
	for (int i = 0; i < N; i++) {
		for (int j = 1; j <= A[i]; j++) {
			if (M[j] == 0 && j < A[i]) cnt++;
		}
		M[A[i]] = 1;
	}
	printf("%lld\n", cnt);

	return 0;
}

