#最无脑的解法,就是考虑余数,余2可以借1,然后喝的总数加1,余1的话就啥也做不了
def sum(n):
    count = 0
    while n >= 2: 
        if n == 2:
            count = count + 1
            break
        count += n//3
        n = n//3 + n%3
        
    return count

while True:
    try:
        array = list()
        while 1 :
            i = int(input())
            if i != 0:
                array.append(i)
            else: break
        for j in array:
            print(sum(j))
    except: break