#include <iostream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

int i, j, k;

vector<vector<int> > tfs(10);
vector<vector<int> > tf(10);
vector<vector<int> > fs(10);
vector<vector<int> > st(10);
vector<int> t(10);
vector<int> f(10);
vector<int> s(10);

int main(void) {
    for (i=0; i<=9; i++) {
        tfs[i] = vector<int>(0);
        tf[i] = vector<int>(0);
        fs[i] = vector<int>(0);
        st[i] = vector<int>(0);
    }
    int N;
    int cnt = 0;
    cin >> N;
    
    for (i = 1; i <= 9; i++) {
        int num=0;
        for (j=0; j<i; j++) {
            num += 3 * pow(10, j);
        }
        t[i] = num;
    }
    for (i = 1; i <= 9; i++) {
        int num=0;
        for (j=0; j<i; j++) {
            num += 5 * pow(10, j);
        }
        f[i] = num;
    }
    for (i = 1; i <= 9; i++) {
        int num=0;
        for (j=0; j<i; j++) {
            num += 7 * pow(10, j);
        }
        s[i] = num;
    }
    for (i = 2; i <= 9; i++) {
        if (i == 2) {
            tf[i].push_back(35);
            tf[i].push_back(53);
        } else {
            for (j=0; j < tf[i-1].size(); j++) {
                tf[i].push_back(tf[i-1][j] + 3 * pow(10, i - 1));
                tf[i].push_back(tf[i-1][j] + 5 * pow(10, i - 1));
            }
            tf[i].push_back(t[i-1] + 5 * pow(10, i - 1));
            tf[i].push_back(f[i-1] + 3 * pow(10, i - 1));
        }
    }
    
    for (i = 2; i <= 9; i++) {
        if (i == 2) {
            fs[i].push_back(57);
            fs[i].push_back(75);
        } else {
            for (j=0; j < fs[i-1].size(); j++) {
                fs[i].push_back(fs[i-1][j] + 5 * pow(10, i - 1));
                fs[i].push_back(fs[i-1][j] + 7 * pow(10, i - 1));
            }
            fs[i].push_back(f[i-1] + 7 * pow(10, i - 1));
            fs[i].push_back(s[i-1] + 5 * pow(10, i - 1));
        }
    }
    for (i = 2; i <= 9; i++) {
        if (i == 2) {
            st[i].push_back(73);
            st[i].push_back(37);
        } else {
            for (j=0; j < st[i-1].size(); j++) {
                st[i].push_back(st[i-1][j] + 7 * pow(10, i - 1));
                st[i].push_back(st[i-1][j] + 3 * pow(10, i - 1));
            }
            st[i].push_back(s[i-1] + 3 * pow(10, i - 1));
            st[i].push_back(t[i-1] + 7 * pow(10, i - 1));
        }
    }
    for (i = 3; i <= 9; i++) {
        if (i == 3) {
            tfs[i].push_back(357);
            tfs[i].push_back(375);
            tfs[i].push_back(537);
            tfs[i].push_back(573);
            tfs[i].push_back(735);
            tfs[i].push_back(753);
        } else {
            for (j=0; j < tfs[i-1].size(); j++) {
                tfs[i].push_back(tfs[i-1][j] + 3 * pow(10, i - 1));
                tfs[i].push_back(tfs[i-1][j] + 5 * pow(10, i - 1));
                tfs[i].push_back(tfs[i-1][j] + 7 * pow(10, i - 1));
            }
            for (j=0; j < tf[i-1].size(); j++) {
                tfs[i].push_back(tf[i-1][j] + 7 * pow(10, i - 1));
            }
            for (j=0; j < fs[i-1].size(); j++) {
                tfs[i].push_back(fs[i-1][j] + 3 * pow(10, i - 1));
            }
            for (j=0; j < st[i-1].size(); j++) {
                tfs[i].push_back(st[i-1][j] + 5 * pow(10, i - 1));
            }
        }
    }
    
    for (i=3; i<=9; i++) {
        for (j=0; j<tfs[i].size(); j++) {
            if (tfs[i][j] <= N) {
                cnt++;
            }
        }
    }
    
    cout << cnt << endl;
    
    return 0;
}

Measured memory_bytes: 512