function main(N){
    return Array.apply(0,new Array(+N)).map((e,i)=>String(i+1)).filter(e=> !e.match(/[0124689]/) && e.match(/(?=.*7+)(?=.*5+)(?=.*3+)/)).length;
}
console.log(main(require('fs').readFileSync('/dev/stdin','utf8')));