#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 <tuple>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

class AliceGame { public:
	long long findMinimumValue(long long x, long long y)
	{
		LL c = (LL)sqrt(x+y);
		for(LL n=max(0LL, c-10); n<=c+10; ++n)
			if(n*n == x+y)
				return solve(int(n), x);
		return -1;
	}

	LL solve(int n, LL x)
	{
		int cnt = 0;
		for(int t=n; t>=1; --t)
		{
			int s = 2*t-1;
			if(s <= x) {
				x -= s;
				cnt ++;
			}
		}
		return cnt;
	}
};

// 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 long long& Expected, const long long& 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(_, AliceGame().findMinimumValue(x, y));}
int main(){

CASE(0)
	long long x = 8LL; 
	long long y = 17LL; 
	long long _ = 2LL; 
END
CASE(1)
	long long x = 17LL; 
	long long y = 8LL; 
	long long _ = 3LL; 
END
CASE(2)
	long long x = 0LL; 
	long long y = 0LL; 
	long long _ = 0LL; 
END
CASE(3)
	long long x = 9LL; 
	long long y = 9LL; 
	long long _ = -1LL; 
END
CASE(4)
	long long x = 500000LL; 
	long long y = 500000LL; 
	long long _ = 294LL; 
END
CASE(5)
	long long x = 0LL; 
	long long y = 4LL; 
	long long _ = 0LL; 
END
CASE(6)
	long long x = 4LL; 
	long long y = 0LL; 
	long long _ = 2LL; 
END
}
// END CUT HERE
