#include <iostream>
#include <algorithm>
using namespace std;

int main() {
    long N;
    cin >> N;
    long a,b,c,i,j,k,l,m,n,counter,num753;
for(l=0;l<10;l++){
for(m=3;m<8;m+=2){
    for(i=3;i<8;i+=2){
        for(j=3;j<8;j+=2){
           if(i!=j){
           for(k=3;k<8;k+=2){
               if(k!=j){
               num753 = (100*i+10*j+k)*(pow(10,l))+m;
               if(N-num753>=0){
                   counter++;
               }
        }
    }

    }
}
}
}
}
cout << counter << endl;
}
