#define ll long long
#define ffor(i,a,b) for (int i=(a);i<(b);i++)
#define rfor(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define rep(i,n) for (int i=0;i<(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#define SIZE 100001
#define MOD 1000000007
#define INF 100000000
using namespace std;
int sx,sy,gx,gy;
//移動方向
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
int card[8];
int d[2][8];
bool visited[101][101];
typedef pair<int,int> P;
int w,h;


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	while(1001){
		rep(i,8) cin >> card[i];
		int count = 0;
		rep(i,7){
			for(int j = 7; j>i; j--){
				if(card[j] < card[j-1]){
					int t = card[j];
					card[j] = card[j-1];
					card[j-1] = t;
					count++;
				}

			}
		}
		cout << count << endl;
	}


	return 0;
}