#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
	string s;
	cin >> s;
	int a[10]={0};
	for(int i=0; i<s.size(); ++i)
	{
		a[s[i]-'0']++;
	}

	if(s.size()==1)
	{
		if(s=="8")
		{
			cout << "Yes" << endl;
			return 0;
		}
	}
	else if(s.size()==2)
	{
		if(((s[0]-'0')*10+(s[1]-'0'))%8==0 || ((s[1]-'0')*10+(s[0]-'0'))%8==0)
		{
			cout << "Yes" << endl;
			return 0;
		}
	}

	for(int i=112; i<1000; i+=8)
	{
		int d1=i/100;
		int d2=i/10%10;
		int d3=i%10;

		int t[10];
		for(int i=0; i<10; ++i)
		{
			t[i]=a[i];
		}

		if(t[d1]>0) t[d1]--;
		else continue;

		if(t[d2]>0) t[d2]--;
		else continue;

		if(t[d3]<=0) continue;

		cout << "Yes" << endl;
		return 0;
	}

	cout << "No" << endl;
	return 0;
}
#include "bits/stdc++.h"
#include "random"
#include <unistd.h>

using namespace std;

#define ll long long
#define vi vector<int>
#define vl vector<long long>
#define vvi vector<vi>
#define pi  pair<int,int>
#define mp  make_pair
#define pb  push_back
#define MOD int(1e9) + 7
#define PAI  3.1415926535
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define chmax(x, y) x = max(x,y)
#define chmin(x, y) x = min(x,y)
#define pr(x) cout << x << endl
#define Endl endl
#define rep(i, n) for(int i = 0 ; i < n; ++i)

const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int ddx[8] = {-1,0,1,-1,1,-1,0,1};
const int ddy[8] = {-1,-1,-1,0,0,1,1,1};
const int inf = 99999999;
const ll linf = 1LL << 62;

ll gcd(ll a,ll b){
  if(a < b)swap(a , b);
  if(a % b != 0) return(gcd(b, a%b));
  return b;
}

ll lcm(ll a,ll b){
  if(a < b)swap(a , b);
  return (a / gcd(a , b)) * b;
}

int Uniform_Random(int a, int b){ // (a <= x <= b)

  random_device rd;
  mt19937 mt(rd());
  
  uniform_int_distribution<int> rv1(a, b);
  return rv1(mt); 
}

bool check(int n){
  while(n){
    if(n % 10 == 7)
      return true;
    n /= 10;
  }
  return false;
}

bool octal(int n){
  while(n){
    if (n % 8 == 7)
      return true;
    n /= 8;
  }
  return false;
}

int main(){

  int N; cin >> N;
  set<int> st;

  for(int i = 1; i <= N; ++i){
    if(check(i)){
      st.insert(i);
      // cout << i << endl;
    }
    else if(octal(i)){
      st.insert(i);
      // cout << i << endl;
      }
  }
  
  cout << N - st.size() << endl;

  return 0;
}