#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"from itertools import*;n=int(input());print(sum(len(set(a))>2and n>=int(''.join(a))for i in range(11)for a in product(*['357']*i)))\n"
"\"";
  system(s);
  return 0;
}            