import java.util.*; import java.lang.*; import java.io.*; public class Main { public static void main (String[] args) throws java.lang.Exception { // your code goes here // 入力 Scanner sc = new Scanner(System.in); int N = sc.nextInt(); // カウント int count = 0; if(N < 100){ count = N / 3 - 3; }else{ count = 30; int id = 16; long num = baseConvert(id) * 3L; while(num <= N){ count++; id++; num = baseConvert(id) * 3L; } } // 出力 System.out.println(count); } // 10進数→4進数変換関数 public static int baseConvert(int num){ int output = 0; int digit = 1; while(num > 0){ int amari = num % 4; output += amari * digit; num = num / 4; digit *= 10; } return output; } }