#include <iostream>
using namespace std;

int main(int argc, char* argv[]){
    int n;
    while(cin >> n){
        if(n == 0){
            break;
        }
        int res = 0;
        while(n > 2){
            int quo = n / 3;
            int remainder = n % 3;
            res += quo;
            n = quo + remainder;
        }
        if(n == 2){
            res += 1;
        }
        cout << res << endl;
    }
    return 0;
}