#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int N = 1e6 + 10;
int t, n, m, k, l, r, op, x, y;
string a, b;
map<string, int>mp = {
{"12345", 1}, {"23456", 2}, {"34567", 3}, {"45678", 4}, {"56789", 5}
};
unordered_map<int, int>smp;
bool f(string&s1, string &s2) {
for (char&ch : s1) {
smp[ch - '0']++;
}
int siz2 = s2.size();
if (siz2 == 5) {
int v2 = mp[s2];
for (int i = v2 + 1; i <= 5; i++) {
bool flag = true;
for (int j = 0; j < 5; j++) {
if (smp[i + j] == 0) {
flag = false;
break;
}
}
if (flag) {
return true;
}
}
} else {
x = s2.back() - '0';
for (int i = x + 1; i <= 9; i++) {
if (smp[i] >= siz2) {
return true;
}
}
}
return false;
}
void solve() {
cin >> a >> b;
cout << (f(a, b) ? "YES" : "NO") << "\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
solve();
return 0;
}