'use strict'

let cnt = 0
let num
let len
const chara = []

const rec = str => {
  if (str.length < len) {
    rec(str + '0')
    rec(str + '3')
    rec(str + '5')
    rec(str + '7')
  } else {
    // console.log(str)
    chara.push(str)
  }
}

const has753 = str => {
  let tmp = ~~str //数値化で先頭の0を削除
  tmp = tmp.toString() // stringに戻す

  return str.indexOf('3') >= 0 &&
    str.indexOf('5') >= 0 &&
    str.indexOf('7') >= 0 &&
    tmp.indexOf('0') < 0
    ? true
    : false
}

function main(input) {
  num = input.split('\n')[0]
  len = num.length
  num = ~~num

  rec('')

  for (let i in chara) {
    if (~~chara[i] <= num && has753(chara[i])) {
      // console.log(~~chara[i])
      cnt++
    }
  }
  console.log(cnt)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))
