#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define REP(i,j,n) for(int i=(j);i<(n);++i)
#define mp make_pair
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
typedef pair<P,int> COST;
#define repl(i,n) for(ll i=0;i<(n);++i)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
using vll=vector<ll>;
using GrafPair=vector<vector<P>>;
using Graf=vector<vll>;
#define MAX 1000000007
#define DOUBLE fixed << setprecision(15)

int main()
{
    ll n;
    cin >> n;
    ll num=sqrt(n+1);
    ll sum=num*(num+1)/2;
    num++;
    while(sum<=n+1){
        sum+=num;
        num++;
    }
    num--;
    if(n==2){
        cout << 1 << endl;
    }else{
        cout << n+2-num << endl;
    }
}
#include<bits/stdc++.h>
using namespace std;
 
int main() {
    long long n;
    cin>>n;
 
    
    if (0==n%3) {
        cout<<"0\n";
        return 0;
    } else if (n<=2) {
        cout<<"-1\n";
        return 0;
    }
 
    
    int cnt[3]={};
    int sum=0;
    int tot=0;
    while (n) {
        int p=n%10;
        n/=10;
        sum+=p;
        tot++;
        cnt[p%3]++;
    }
 
    if (1==sum%3) {
        if (tot>1 && cnt[1]>=1) {
            cout<<"1\n";
        } else if (tot>2 && cnt[2]>=2) {
            cout<<"2\n";
        } else {
            cout<<"-1\n";
        }
    } else if (2==sum%3) {
        if (tot>1 && cnt[2]>=1) {
            cout<<"1\n";
        } else if (tot>2 && cnt[1]>=2) {
            cout<<"2\n";
        } else {
            cout<<"-1\n";
        }
    }
 
    return 0;
} 
