#include int main ( void ) { int M , N; int Count = 0; int L; bool bOK = true; scanf ( "%d %d" , &M , &N ); while ( 1 ) { if ( ( M == 0 ) || ( N == 0 ) ) { bOK = false; break; } if ( N == 1 ) { Count += M - 1; break; } L = M / N; if ( M % N == 0 ) { Count += L - 1; break; } M -= N*L; Count += L; //交換(逆数) L = M; M = N; N = L; Count++; } if ( bOK ) printf ( "%d\n" , Count ); else printf ( "-1\n" ); return 0; }