import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        while (scan.hasNext()){
            int s = scan.nextInt();
            if(s == 0) continue;
            System.out.println(recWaterBottle(s,0));
        }
    }
    
    //使用递归
    private static int recWaterBottle(int s,int c){
        if (s <= 1) return c;
        int d = (s==2 ? s+1 : s) / 3;
        s = (s==2 ? s+1 : s) % 3 + d;
        c = c + d;
        return recWaterBottle(s,c);
    }
}