def myfun(s):
    count = s // 3
    
    if s//3+s%3 ==2: # 递归结束条件
        count += 1 
    elif s//3+s%3 == 1: # 递归结束条件
        count += 0
    else:
        count += myfun(s//3+s%3) # 递归
    return count

while True:
    s = eval(input())
    if s == 0:
        break
    else:
        count = myfun(s)
        print(count)