function Main(input) {
	var inputInt = parseInt(input, 10);
	var count = 0;
  	var max = parseInt('1000000000', 4);
    for(var i = 0; i <= max; i++) {
      var num4 = i.toString(4);
      if (num4.indexOf('0') >= 0 ) {
        continue;
      }
      num4 = num4.replace(/3/g, '7').replace(/2/g, '5').replace(/1/g, '3')
      if (parseInt(num4, 10) > inputInt) {
        break;
      }
      var a7 = num4.indexOf('7');
      var a5 = num4.indexOf('5');
      var a3 = num4.indexOf('3');
      if (a7 >= 0 && a5 >= 0 && a3 >= 0) {
      	count++;
      }
    }
    console.log(count);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));