#include<bits/stdc++.h> using namespace std; int main(){ int k=1,b,sum; while(k){ sum=0; cin>>b; if(b==0) break; while(b/3){ sum+=b/3; b=b/3+b%3; } if(b%3==2) cout<<sum+1<<endl; else cout<<sum<<endl; } return 0; }