#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];
string s;
char toAdd[3] = {'3','5','7'};
int solve(int idx,int any,bool three,bool five,bool seven,int num)
{
//cout << num << " " << any << endl;
    if(idx == s.length())
        return (three && five && seven);
    int C = (three && five && seven);
    if(any == 0){
            if(idx < s.length()-1){
        C += solve(idx + 1,(s[idx] > '3' ? 2 : (s[idx] == '3' ? 0 : 1)),true,five,seven,num*10 + 3);
        C += solve(idx + 1,(s[idx] > '5' ? 2 : (s[idx] == '5' ? 0 : 1)),three,true,seven,num*10+5);
        C += solve(idx + 1,(s[idx] > '7' ? 2 : (s[idx] == '7' ? 0 : 1)),three,five,true,num*10+7);
            } else {
                if(s[idx] >= '3')
                   C += solve(idx + 1,(s[idx] > '3' ? 2 : (s[idx] == '3' ? 0 : 1)),true,five,seven,num*10 + 3);
                   if(s[idx] >= '5')
        C += solve(idx + 1,(s[idx] > '5' ? 2 : (s[idx] == '5' ? 0 : 1)),three,true,seven,num*10+5);
        if(s[idx] >= '7')
        C += solve(idx + 1,(s[idx] > '7' ? 2 : (s[idx] == '7' ? 0 : 1)),three,five,true,num*10+7);
            }
    } else if(any == 2)
    {
        C += solve(idx + 1,2,true,five,seven,num*10 + 3);
        C += solve(idx + 1,2,three,true,seven,num*10+5);
        C += solve(idx + 1,2,three,five,true,num*10+7);
    }else if(any == 1)
    {
        if(idx < s.length()-1)
        {
            C += solve(idx + 1,1,true,five,seven,num*10 + 3);
        C += solve(idx + 1,1,three,true,seven,num*10+5);
        C += solve(idx + 1,1,three,five,true,num*10+7);
        }
    }
    return C;
}
int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> s;
    cout << solve(0,0,false,false,false,0);
    return 0;
}


Measured memory_bytes: 256