#include <iostream>
using namespace std;
int main(){
int N;
while(cin >> N){
if(N == 0) return 0;
int count = 0;
while(N >= 3){
count += N / 3;
N = N / 3 + N % 3;
}
if(N == 2)
count++;
cout << count << endl;
}
}