#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <cstring>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

class CoinsExchange { public:
	int countExchanges(int G1, int S1, int B1, int G2, int S2, int B2) 
	{
		if( G1 < G2 ) {
			int n = G2-G1;
			return check2( S1, B1, S2+n*11, B2, n ); // 11*n silver needed
		}
		if( B1 < B2 ) {
			int n = (B2-B1+8)/9;
			return check2( G1, S1, G2, S2+n, n ); // n silver needed
		}

		// need silver
		int n = 0;
		while( S1<S2 && G1- 1>=G2 ) S1+=9, G1-= 1, n++;
		while( S1<S2 && B1-11>=B2 ) S1+=1, B1-=11, n++;
		return S1<S2 ? -1 : n;
	}

	int check2(int S1, int B1, int S2, int B2, int acc)
	{
		if( S1 < S2 ) {
			int n = S2-S1;
			return B2<=B1-n*11 ? n+acc : -1;
		}
		if( B1 < B2 ) {
			int n = (B2-B1+8)/9;
			return S2<=S1-n ? n+acc : -1;
		}
		return acc;
	}
};

// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
 { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
 { os << "{ ";
   for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
   os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const int& Expected, const int& Received) {
 bool ok = (Expected == Received);
 if(ok) cerr << "PASSED" << timer() << endl;  else { cerr << "FAILED" << timer() << endl;
 cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END	 verify_case(_, CoinsExchange().countExchanges(G1, S1, B1, G2, S2, B2));}
int main(){

CASE(0)
	int G1 = 1; 
	int S1 = 0; 
	int B1 = 0; 
	int G2 = 0; 
	int S2 = 0; 
	int B2 = 81; 
	int _ = 10; 
END
CASE(1)
	int G1 = 1; 
	int S1 = 100; 
	int B1 = 12; 
	int G2 = 5; 
	int S2 = 53; 
	int B2 = 33; 
	int _ = 7; 
END
CASE(2)
	int G1 = 1; 
	int S1 = 100; 
	int B1 = 12; 
	int G2 = 5; 
	int S2 = 63; 
	int B2 = 33; 
	int _ = -1; 
END
CASE(3)
	int G1 = 5; 
	int S1 = 10; 
	int B1 = 12; 
	int G2 = 3; 
	int S2 = 7; 
	int B2 = 9; 
	int _ = 0; 
END

}
// END CUT HERE
