program main
   implicit none
   integer:: n,i,j,count(4)=0,nnew,summ=0,dummy1,dummy2
   
   read(*,*)n
   do i=1,n
     count(1:3)=0;count(4)=1
     do j=int(log10(real(i))),0,-1
        if(j==int(log10(real(i))))dummy2=i
        nnew=dummy2/10**j
        dummy2=dummy2-nnew*10**j
        
        if(nnew==3)then;count(1)=1;cycle;endif
        if(nnew==5)then;count(2)=1;cycle;endif
        if(nnew==7)then;count(3)=1;cycle;endif
        if(nnew/=3 .and. nnew/=5 .and. nnew/=7)count(4)=0
  !      write(*,*)nnew
     enddo
     if(all(count==1))then
        summ=summ+1
        write(*,*)i
     endif
   enddo
   write(*,*)summ
end program main
