#include <iostream>
#include <cmath>
#include <queue>
#include <cstdio>
#include <cstring>
#include <algorithm>

#define INF 0x7f7f7f7f
#define PI acos(-1.0)

#define L(x)    (x) << 1
#define R(x)    (x) << 1 | 1
#define lowbit(x)   (x)&(-x)
#define Mid(l, r)   (l + r) >> 1
#define Min(x, y)   (x) < (y) ? (x) : (y)
#define Max(x, y)   (x) < (y) ? (y) : (x)
#define iabs(x)     (x) < 0 ? -(x) : (x)
#define CLR(arr, val)    memset(arr, val, sizeof(arr))

using namespace std;

int main()
{
	int num[10];
	while (~scanf("%d", &num[0])) {
		int ans = 0;
		
		for (int i = 1; i < 8; i++)	
			scanf("%d", &num[i]);
		for (int i = 0; i < 7; i++) {
			for (int j = i + 1; j < 8; j++) {
				if (num[i] > num[j])	ans++;
			} 
		}
		cout << ans << endl;
	}
	return 0;
}