#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<int,int> ,null_type,less<pair<int,int> >,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
long long MOD = 1e9+7;
pair<int,int> dx[4] = {{1,0},{-1,0},{0,1},{0,-1}};
long long fastpow(long long x,long long k)
{
    if(!k)
        return 1;
    if(k & 1)
        return ((x * fastpow(x,k-1) % MOD) % MOD) % MOD;
    long long ans = fastpow(x,k/2);
    ans %= MOD;
    ans *= ans;
    ans %= MOD;
    return ans;
}
long long sumF(long long x)
{
    int s = 0;
    while(x)
        s += x%10,x /= 10;
    return s;
}
void convert(int x,int base)
{
    if(x == 0)
        return;
    convert(x / base,base);
    cout << x%base;
    return;
}
struct hashFunc
{
    string s;
    vector<long long> prefixHash;
    vector<long long> suffixHash;
    long long MOD;
    long long p;
    vector<long long> hashPower;

};
void setPrefixHash(hashFunc& hashStruct)
{
    hashStruct.prefixHash.resize(hashStruct.s.length());
    long long curSum = 0;
    for(int i = 0;i < hashStruct.s.length();i++)
        curSum = ((curSum * hashStruct.p) % hashStruct.MOD + (hashStruct.s[i])) % hashStruct.MOD,hashStruct.prefixHash[i] = curSum;
}
void setSuffixHash(hashFunc& hashStruct)
{
    hashStruct.suffixHash.resize(hashStruct.s.length());
    long long curSum = 0;
    for(int i = hashStruct.s.length()-1;i >= 0;i--)
        curSum = ((curSum * hashStruct.p) + (hashStruct.s[i])) % hashStruct.MOD,hashStruct.suffixHash[hashStruct.s.length() - i - 1] = curSum;
}
long long getHash(int l,int r,hashFunc& hashStruct,bool isSuffix)
{
    if(!isSuffix)
    {
        long long enddy = hashStruct.prefixHash[r] % hashStruct.MOD;
        long long starto = (l ? hashStruct.prefixHash[l-1] : 0);
        starto = (starto * hashStruct.hashPower[r-l+1]) % hashStruct.MOD;
        return (((enddy - starto) % hashStruct.MOD) + hashStruct.MOD) % hashStruct.MOD;
    } else
    {
        r = hashStruct.s.length() - r - 1;
        l = hashStruct.s.length() - l - 1;
        if(l > r)
            swap(l,r);
        long long enddy = hashStruct.suffixHash[r];
        long long starto = (l ? hashStruct.suffixHash[l-1] : 0);
        starto = (starto * hashStruct.hashPower[r-l+1]) % hashStruct.MOD;
        return (((enddy - starto) % hashStruct.MOD) + hashStruct.MOD) % hashStruct.MOD;
    }
}
void readyHashPower(long long m,long long pp,hashFunc& hashStruct)
{
    hashStruct.MOD = m;
    hashStruct.p = pp;
    hashStruct.hashPower.resize(hashStruct.s.length()+1);
    hashStruct.hashPower[0] = 1;
    for(int i = 1;i < hashStruct.hashPower.size();i++)
        hashStruct.hashPower[i] = (hashStruct.hashPower[i-1] * hashStruct.p) % hashStruct.MOD;
}
//dp[i][j][k] = dp[i-1][j-1][s-i] + dp[i-1][j][s];
map<int,int> vis;
int digit(int k)
{
    set<int> ff;
    while(k)
    {
        ff.insert(k % 10);
        k /= 10;
    }
     return ff.size();
}
int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n;
    cin >> n;
    queue<int> myQue;
    myQue.push(0);
    int ans = 0;
    while(myQue.size())
    {
        int top = myQue.front();
        myQue.pop();
        if(!vis[top*10 + 3] && (top * 10 + 3) <= n)
        {
            myQue.push(top*10+3);
            vis[top*10+3] = true;
            ans += (digit(top*10+3) == 3);
        }
        if(!vis[top*10 + 5] && (top * 10 + 5) <= n)
        {
            myQue.push(top*10+5);
            vis[top*10+5] = true;
            ans += (digit(top*10+5) == 3);
        }
        if(!vis[top*10 + 7] && (top * 10 + 7) <= n)
        {
            myQue.push(top*10+7);
            vis[top*10+7] = true;
            ans += (digit(top*10+7) == 3);
        }
    }
    cout << ans;
    return 0;
}
