#include <iostream>
using namespace std;

int main() {
    int a = 0;
    int count = 0;
    while (cin >> a) { // 注意 while 处理多个 case
        count = 0;
        if (a == 0)
            break;
        while (a > 1)
        {
            if (a == 2)
            {
                count += 1;
                break;
            }

            int temp = 0;
            temp = a / 3;

            count += temp;
            a = a % 3 + temp;
        }
        cout << count << endl;
    }
}
// 64 位输出请用 printf("%lld")