function main(input) {
  var N = input[0]-0; 9
  var nums = ["7","5","3"];
  console.log(calc(N,nums,[], false));
}

function calc(N, nums, arr, ngs){
  var ans = 0;
  var base = arr.join("");
  for(var i=0;i<nums.length;i++){
    var n = (base+nums[i]);
    var cnc = arr.concat(nums[i]);
    if(n-0<=N){
      if(ngs){
        ans++;
        ans += calc(N,nums, cnc,true);
      }else if((cnc.indexOf("3")>=0 && cnc.indexOf("5")>=0 && cnc.indexOf("7")>=0)){
        ans++;
        ans += calc(N,nums, cnc,true);
      }else {
        ans += calc(N,nums, cnc,false);
      }
    }
  }
  return ans;
}

main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))
