#include <stdio.h>
#include <stdlib.h>

#define MaxNum 200000

extern int bubbleSort(unsigned long int A[], unsigned long int Num, unsigned long int start);



int main( void )
{
    unsigned long int num=0;
    unsigned long int start=0;
    unsigned long int i=0;
    unsigned long int cnt = 0;    // 反転数
    
    unsigned long A[MaxNum] = {};
    
    scanf("%lu",&num);
    if(num == 0)
    {
        printf("0\n");
        return 0;
    }
    
    for(i=1; i<num; i++)
    {
        scanf("%lu", &A[i]);
    }
    
    for(i=1; i<num; i++)
    {
        if(A[i-1] > A[i])
        {
            start=i-1;
            break;
        }
    }
    
    cnt = bubbleSort(A, num, start);

    printf("%lu", cnt);
    
    return 0;
}

int bubbleSort(unsigned long int A[], unsigned long int Num, unsigned long int start)
{
    unsigned long int cnt = 0;    // 反転数
    unsigned long int i,j = 0;
    unsigned long int tmp = 0;
    
    
    for(i=start; i < Num; i++)
    {
        for(j=Num-1; j>i; j--)
        {
            if( A[j] < A[j-1] )
            {
                tmp = A[j];
                A[j] = A[j-1];
                A[j-1] = tmp;
                
                cnt++;
            }
        }
    }
    return cnt;
}
