def get_ans(n):
    ans=0
    if n<2:return 0
    elif n==2:return 1
    else:
        ch = n // 3  # 可换的瓶子
        a = n // 3 + n % 3  # 换完后的空瓶
        ch += get_ans(a)
        return int(ch)

if __name__=='__main__':
    while True:
        n = int(input())
        if n == 0:
            break
        print(get_ans(n))