#include using namespace std; template T gcd(T a, T b){ while(b){ T tmp = b; b = a % b; a = tmp; } return a; } int main(){ int m, n; cin >> m >> n; int g = gcd(m, n); m /= g; n /= g; int ans = 0; while(n != m){ if(n <= m) m -= n; else swap(m, n); ans++; } cout << (m == 0 || n == 0 ? -1 : ans) << endl; }