#include<bits/stdc++.h>
using namespace std;

string S;
//          pos, less?,3?,5?,7?
long long dp[12][2][2][2][2];
int main(){
	cin >> S;

	for(long long i = 0; i < S.size(); i++){
		long long num = atol(S.substr(i,1).c_str());

		//put 3
		if(num < 3){
			for(int three = 0; three <=1; three++){
				for(int five = 0; five <=1 ; five++){
					for(int seven = 0; seven <= 1; seven++){
						//from less -> less
						dp[i + 1][1][1][five][seven] += dp[i][1][three][five][seven];
					}
				}
			}
			if(i != 0){
				//from zero
				dp[i+1][1][1][0][0] += 1;
			}
		}else if(num == 3){
			for(int three = 0; three <=1; three++){
				for(int five = 0; five <=1 ; five++){
					for(int seven = 0; seven <= 1; seven++){
						//from less -> less
						dp[i + 1][1][1][five][seven] += dp[i][1][three][five][seven];
						//from giri -> giri
						dp[i + 1][0][1][five][seven] += dp[i][0][three][five][seven];
					}
				}
			}
			//from zero
			if(i == 0){
				dp[i+1][0][1][0][0] += 1;
			}else{
				dp[i+1][1][1][0][0] += 1;
			}
		}else{
			for(int three = 0; three <=1; three++){
				for(int five = 0; five <=1 ; five++){
					for(int seven = 0; seven <= 1; seven++){
						//from less -> less
						dp[i + 1][1][1][five][seven] += dp[i][1][three][five][seven];
						//from giri -> less
						dp[i + 1][1][1][five][seven] += dp[i][0][three][five][seven];
					}
				}
			}
			//from zero
			dp[i+1][1][1][0][0] += 1;
		}

		//put5
		if(num < 5){
			for(int three = 0; three <=1; three++){
				for(int five = 0; five <=1 ; five++){
					for(int seven = 0; seven <= 1; seven++){
						//from less -> less
						dp[i + 1][1][three][1][seven] += dp[i][1][three][five][seven];
					}
				}
			}
			if(i != 0){
				//from zero
				dp[i+1][1][0][1][0] += 1;
			}
		}else if(num == 5){
			for(int three = 0; three <=1; three++){
				for(int five = 0; five <=1 ; five++){
					for(int seven = 0; seven <= 1; seven++){
						//from less -> less
						dp[i + 1][1][three][1][seven] += dp[i][1][three][five][seven];
						//from giri -> giri
						dp[i + 1][0][three][1][seven] += dp[i][0][three][five][seven];
					}
				}
			}
			//from zero
			if(i == 0){
				dp[i+1][0][0][1][0] += 1;
			}else{
				dp[i+1][1][0][1][0] += 1;
			}
		}else{
			for(int three = 0; three <=1; three++){
				for(int five = 0; five <=1 ; five++){
					for(int seven = 0; seven <= 1; seven++){
						//from less -> less
						dp[i + 1][1][three][1][seven] += dp[i][1][three][five][seven];
						//from giri -> less
						dp[i + 1][1][three][1][seven] += dp[i][0][three][five][seven];
					}
				}
			}
			//from zero
			dp[i+1][1][0][1][0] += 1;
		}


		//put7
		if(num < 7){
			for(int three = 0; three <=1; three++){
				for(int five = 0; five <=1 ; five++){
					for(int seven = 0; seven <= 1; seven++){
						//from less -> less
						dp[i + 1][1][three][five][1] += dp[i][1][three][five][seven];
					}
				}
			}
			if(i != 0){
				//from zero
				dp[i+1][1][0][0][1] += 1;
			}
		}else if(num == 7){
			for(int three = 0; three <=1; three++){
				for(int five = 0; five <=1 ; five++){
					for(int seven = 0; seven <= 1; seven++){
						//from less -> less
						dp[i + 1][1][three][five][1] += dp[i][1][three][five][seven];
						//from giri -> giri
						dp[i + 1][0][three][five][1] += dp[i][0][three][five][seven];
					}
				}
			}
			//from zero
			if(i == 0){
				dp[i+1][0][0][0][1] += 1;
			}else{
				dp[i+1][1][0][0][1] += 1;
			}
		}else{
			for(int three = 0; three <=1; three++){
				for(int five = 0; five <=1 ; five++){
					for(int seven = 0; seven <= 1; seven++){
						//from less -> less
						dp[i + 1][1][three][five][1] += dp[i][1][three][five][seven];
						//from giri -> less
						dp[i + 1][1][three][five][1] += dp[i][0][three][five][seven];
					}
				}
			}
			//from zero
			dp[i+1][1][0][0][1] += 1;
		}





		//for(int less = 0; less <=1 ; less++){
		//	for(int three = 0; three <=1; three++){
		//		for(int five = 0; five <=1 ; five++){
		//			for(int seven = 0; seven <= 1; seven++){
		//			cout << "dp[" << i+1 <<"][" << less << "][" << three << "][" << five << "][" << seven << "]=" << dp[i+1][less][three][five][seven] << endl;
		//			}
		//		}
		//	}
		//}
	}
	cout << dp[S.size()][0][1][1][1] + dp[S.size()][1][1][1][1] << endl;
}


Measured memory_bytes: 256