#include <iostream>
using namespace std;
class Solution {
public:
int reachNumber(int target) {
if(target < 0) target = -target;
int sum = 0, k = 1;
while(sum < target) sum += k ++;
if(sum == target || (sum - target) % 2 == 0) return k - 1;
for(;;){
sum += k ++;
if((sum - target) % 2 == 0) return k - 1;
}
return -1;
}
};
int main() {
cout << Solution().reachNumber(4) << endl;
cout << Solution().reachNumber(5) << endl;
return 0;
}