#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define dbg(x) cout<<#x<<" : "<<x<<endl
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define inf 1000000000000000000
priority_queue<ll,vector<ll>,greater<int>> qp;
priority_queue<ll> qr;
#define maxn 100005
#define mod 1000000007
#define cnt_ones __builtin_popcount
int main(){
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
ll S;
cin>>S;
ll maax = (ll)sqrt(8*S+1);
maax = (maax-1)/2;
for(ll n=maax;n>=1;n--){
ll tu = 2*S-n-n*n;
ll mau = 2*(n+1);
if(tu%mau==0){
if(tu==0) cout<<n;
else cout<<n+1;
return 0;
}
}
cout<<0;
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2RlZmluZSBsbCBsb25nIGxvbmcgCiNkZWZpbmUgZGJnKHgpIGNvdXQ8PCN4PDwiIDogIjw8eDw8ZW5kbAojZGVmaW5lIHJlcChpLGEsYikgZm9yKGludCBpPShhKTtpPD0oYik7aSsrKQojZGVmaW5lIGluZiAxMDAwMDAwMDAwMDAwMDAwMDAwCnByaW9yaXR5X3F1ZXVlPGxsLHZlY3RvcjxsbD4sZ3JlYXRlcjxpbnQ+PiBxcDsKcHJpb3JpdHlfcXVldWU8bGw+IHFyOwojZGVmaW5lIG1heG4gMTAwMDA1CiNkZWZpbmUgbW9kIDEwMDAwMDAwMDcKI2RlZmluZSBjbnRfb25lcyBfX2J1aWx0aW5fcG9wY291bnQKaW50IG1haW4oKXsKICAgIC8vIGZyZW9wZW4oImlucHV0LnR4dCIsInIiLHN0ZGluKTsKICAgIC8vIGZyZW9wZW4oIm91dHB1dC50eHQiLCJ3IixzdGRvdXQpOwogICAgbGwgUzsKICAgIGNpbj4+UzsKICAgIGxsIG1hYXggPSAobGwpc3FydCg4KlMrMSk7CiAgICBtYWF4ID0gKG1hYXgtMSkvMjsKICAgIGZvcihsbCBuPW1hYXg7bj49MTtuLS0pewogICAgICAgIGxsIHR1ID0gMipTLW4tbipuOwogICAgICAgIGxsIG1hdSA9IDIqKG4rMSk7CiAgICAgICAgaWYodHUlbWF1PT0wKXsKICAgICAgICAgICAgaWYodHU9PTApIGNvdXQ8PG47CiAgICAgICAgICAgIGVsc2UgY291dDw8bisxOwogICAgICAgICAgICByZXR1cm4gMDsKICAgICAgICB9CiAgICB9CiAgICBjb3V0PDwwOwogICAgcmV0dXJuIDA7Cn0=