#先对原始数量整除3,将除余和整除数相加,继续整除,直到整除数为0 且余数<2

srsz = []
while True:
    try:
        sr = int(input())
        srsz.append(sr)
    except Exception as e:
        break
    
for zzs in srsz:
    if zzs == 0:
        break
    hldsp = 0
    while True:
        zc = zzs // 3
        hldsp += zc
        cy = zzs % 3
        zzs = zc + cy
        if zzs < 2:
            break
        elif zzs == 2:
            hldsp += 1
            break
        else:
            pass
    print(hldsp)