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