#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int INF = 1001001001;
const ll mod = 1e+9 + 7;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

string s;
int dp[15][2][2][2][2];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> s;
    int n = s.length();

    dp[0][1][0][0][0] = 1;
    for(int d = 0; d < n; ++d){
        int num = s[d] - '0';

        dp[d+1][0][0][0][0] = 1;

        if(num > 3){
            for(int i = 0; i < 2; ++i){
                for(int j = 0; j < 2; ++j){
                    dp[d+1][0][1][i][j] += dp[d][0][0][i][j];
                    dp[d+1][0][1][i][j] += dp[d][1][0][i][j];
                    dp[d+1][0][1][i][j] += dp[d][0][1][i][j];
                    dp[d+1][0][1][i][j] += dp[d][1][1][i][j];
                }
            }
        }
        else if(num == 3){
            for(int i = 0; i < 2; ++i){
                for(int j = 0; j < 2; ++j){
                    dp[d+1][0][1][i][j] += dp[d][0][0][i][j];
                    dp[d+1][0][1][i][j] += dp[d][0][1][i][j];
                    dp[d+1][1][1][i][j] += dp[d][1][0][i][j];
                    dp[d+1][1][1][i][j] += dp[d][1][1][i][j];
                }
            }
        }
        else{   // num < 3
            for(int i = 0; i < 2; ++i){
                for(int j = 0; j < 2; ++j){
                    dp[d+1][0][1][i][j] += dp[d][0][0][i][j];
                    dp[d+1][0][1][i][j] += dp[d][0][1][i][j];
                }
            }
        }
        
        if(num > 5){
            for(int i = 0; i < 2; ++i){
                for(int j = 0; j < 2; ++j){
                    dp[d+1][0][i][1][j] += dp[d][0][i][0][j];
                    dp[d+1][0][i][1][j] += dp[d][1][i][0][j];
                    dp[d+1][0][i][1][j] += dp[d][0][i][1][j];
                    dp[d+1][0][i][1][j] += dp[d][1][i][1][j];
                }
            }
        }
        else if(num == 5){
            for(int i = 0; i < 2; ++i){
                for(int j = 0; j < 2; ++j){
                    dp[d+1][0][i][1][j] += dp[d][0][i][0][j];
                    dp[d+1][0][i][1][j] += dp[d][0][i][1][j];
                    dp[d+1][1][i][1][j] += dp[d][1][i][0][j];
                    dp[d+1][1][i][1][j] += dp[d][1][i][1][j];
                }
            }
        }
        else{   // num < 5
            for(int i = 0; i < 2; ++i){
                for(int j = 0; j < 2; ++j){
                    dp[d+1][0][i][1][j] += dp[d][0][i][0][j];
                    dp[d+1][0][i][1][j] += dp[d][0][i][1][j];
                }
            }
        }

        if(num > 7){
            for(int i = 0; i < 2; ++i){
                for(int j = 0; j < 2; ++j){
                    dp[d+1][0][i][j][1] += dp[d][0][i][j][0];
                    dp[d+1][0][i][j][1] += dp[d][1][i][j][0];
                    dp[d+1][0][i][j][1] += dp[d][0][i][j][1];
                    dp[d+1][0][i][j][1] += dp[d][1][i][j][1];
                }
            }
        }
        else if(num == 7){
            for(int i = 0; i < 2; ++i){
                for(int j = 0; j < 2; ++j){
                    dp[d+1][0][i][j][1] += dp[d][0][i][j][0];
                    dp[d+1][0][i][j][1] += dp[d][0][i][j][1];
                    dp[d+1][1][i][j][1] += dp[d][1][i][j][0];
                    dp[d+1][1][i][j][1] += dp[d][1][i][j][1];
                }
            }

        }
        else{   // num < 7
            for(int i = 0; i < 2; ++i){
                for(int j = 0; j < 2; ++j){
                    dp[d+1][0][i][j][1] += dp[d][0][i][j][0];
                    dp[d+1][0][i][j][1] += dp[d][0][i][j][1];
                }
            }
        }
    }

    cout << dp[n][0][1][1][1] + dp[n][1][1][1][1] << "\n";
}

Measured memory_bytes: 256