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

int main() {
    string s1, s2;
    while (cin >> s1 >> s2) {
        int len = s2.size();
        int flag = 0;
        if (len == 1) {

            int a = s2[0] - '0';
            
            for (int i = a + 1; i <= 9; i++) {
                string s = "";
                char c = '0' + i;
                s = s + c;
                if (s1.find(s) != string::npos) {
                    flag = 1;
                    break;
                }

            }
        } else if (len == 2) {
            int a = s2[0] - '0';
            
            for (int i = a + 1; i <= 9; i++) {
                string s = "";
                char c = '0' + i;
                s = s + c + c;
                if (s1.find(s) != string::npos) {
                    flag = 1;
                    break;
                }

            }
        } else if (len == 3) {
            int a = s2[0] - '0';
            
            for (int i = a + 1; i <= 9; i++) {
                string s = "";
                char c = '0' + i;
                s = s + c + c + c;
     //           cout<<s<<endl;
                if (s1.find(s) != string::npos) {
                    flag = 1;
                    break;
                }

            }
        } else if (len == 4) {
            int a = s2[0] - '0';
            
            for (int i = a + 1; i <= 9; i++) {
                string s = "";
                char c = '0' + i;
                s = s + c + c + c + c;
                if (s1.find(s) != string::npos) {
                    flag = 1;
                    break;
                }

            }
        } else {
            int a = s2[0] - '0';
            bool is[10]={0};
            string ss1 = "";
            for(int i = 0;i<s1.size();i++)
            {
                int num = s1[i]-'0';
                if(!is[num])
                {
                    char c = num + '0';
                    is[num]=1;
                    ss1 = ss1 +c;
                }

            }
       //     cout<<ss1<<endl;
            s1 = ss1;
            for (int i = a + 1; i <= 5; i++) {
                string s = "";
                char c1 = '0' + i;
                char c2 = '0' + i + 1;
                char c3 = '0' + i + 2;
                char c4 = '0' + i + 3;
                char c5 = '0' + i + 4;
                s = s + c1 + c2 + c3 + c4 + c5;
                
                if (s1.find(s) != string::npos) {
                    flag = 1;
                    break;
                }
            }
        }
        if(flag)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }

}
// 64 位输出请用 printf("%lld")