#pragma GCC optimize ("O2")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	if ((tmp & ma0) ^ ma0) {
		int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
		tmp = tmp << dig & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += (72 - dig >> 3);
	}
	else {
		tmp = tmp & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += 8;
		if ((ct = *ci++) >= '0') {
			tmp = tmp * 10 + ct - '0';
			if ((ct = *ci++) >= '0') {
				tmp = tmp * 10 + ct - '0';
				ci++;
			}
		}
	}
	return tmp;
}
ll tmp[200001];
void pakuri_sort(int N, ll A[]) {
	const int b = 8;
	rep(k, 4) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
	}
}
bitset<400010> ST;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);


	int N = getint(), M = getint();
	ll XY[200000];
	int k = 0;
	int nm1 = N - M, nm2 = N + M;
	rep(i, M) {
		int x = getint();
		int y = getint();
		if (y < nm1 | y > nm2) continue;
		XY[k++] = x | (ll)(y - N + 200001) << 32;
	}
	M = k;
	pakuri_sort(M, XY);

	ST[200001] = 1;
	const ll ma = (1ll << 32) - 1;
	int m = 0;
	while (m < M) {
		int m0 = m;
		int x = (XY[m] & ma);
		while (m < M && (XY[m] & ma) == x) {
			int y = (XY[m] >> 32);
			if (ST[y - 1] | ST[y + 1]) XY[m] |= 1ll;
			else if (ST[y]) XY[m] &= (~1ll);
			else XY[m] = 0;
			m++;
		}
		for (int p = m0; p < m; p++) {
			int y = (XY[p] >> 32);
			if (XY[p] & 1) ST[y] = 1;
			else if (XY[p]) ST[y] = 0;
		}
	}
	int kotae = ST.count();
	printf("%d\n", kotae);

	Would you please return 0;
}
#include <bits/stdc++.h>
using namespace std;

#ifdef _DEBUG
#define dout cout
#define debug() if (true)
#define dvout(v) vout(v)
#else
#define dout if (false) cout
#define debug() if (false)
#define dvout(v) if(false) vout(v)
#endif

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define vout(v)           \
	for (auto &i : v)     \
	{                     \
		cout << i << " "; \
	}                     \
	cout << "\n"; //配列出力
#define vec(v, n) vector<int> v(n, 0);
#define vecll(v, n) vector<ll> v(n, 0);
#define vecvec(v,n,m) vector<vector<int>> v(n, vector<int>(m));
#define vin(v)        \
	for (auto &i : v) \
		cin >> i; //配列入力

#define mod (ll)(1e9+7)
typedef long long ll;
typedef unsigned long long ull;
#define next asdnext
#define prev asdprev
#define _n "\n"
#define _n2 "\n\n"
#define _t "\t"

//	LLONG_MAX 9.2*1e18	9223372036854775807LL = (2^63)-1
//	INT_MAX 2.1*1e9 2147483647 = (2^31)-1
//	O(1e8) 1.2sec
void test(ull,ull,ull);

//#define FOR_CODEFORCES
void Main()
{
	string S;
	cin>>S;

	if(S.size()==1){
		if(S[0]=='8')cout<<"Yes"<<endl;
		else cout<<"No"<<endl;

		return;
	}

	if(S.size()==2){
		int a=(S[0]-'0')*10 + (S[1]-'0');
		int b=(S[1]-'0')*10 + (S[0]-'0');

		
		if(a%8==0 || b%8==0)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;

		return;
	}

	
	if(S.size()==3){
		int a=S[0]-'0';
		int b=S[1]-'0';
		int c=S[2]-'0';
		int nums[6];
		nums[0]=a*100+b*10+c;
		nums[1]=a*100+c*10+b;
		nums[2]=b*100+a*10+c;
		nums[3]=b*100+c*10+a;
		nums[4]=c*100+b*10+a;
		nums[5]=c*100+a*10+b;

		rep(i,6){
			if(nums[i]%8==0){
				cout<<"Yes"<<endl;
				return;
			}
		}
		cout<<"No"<<endl;
		return;
	}

	int flags[10]={};


	rep(i,S.size()){
		flags[S[i]-'0']++;
	}

	for(int i=0; i<1000; i+=8){
		int a,b,c;
		a=i/100;
		b=(i%100)/10;
		c=(i%10);
		int flags2[10]={};
		flags2[a]++;
		flags2[b]++;
		flags2[c]++;
		bool isOK=true;
		rep(j,10){
			isOK &= (flags[j]>=flags2[j]);
		}
		if(isOK){
			cout<<"Yes"<<endl;
			return;
		}

	}

	
	cout<<"No"<<endl;
}


void test(){
}
int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << std::fixed << std::setprecision(15);
	#ifdef FOR_CODEFORCES
	int t=0;
	cin>>t;
	rep(i,t)Main();
	#else
	Main();
	#endif
	return 0;
}
