#include <iostream>
using namespace std;

bool myFind(string myCards,int n){
    string target = to_string(n);
    for(int i =0;i<target.length();i++)
        if(myCards.find(target[i])== -1)
            return false;
    return true;
}

int main() {
    string myCards;cin>>myCards;
    string opponentCards;cin>>opponentCards;
    if(opponentCards.length() == 5){
        //出的是顺子
        int arr[5]={12345,23456,34567,45678,56789};
        int oIndex = -1;
        for(int i =0;i<5;i++)
            if(arr[i] == stoi(opponentCards)){
                oIndex = i;
                break;
            }
        for(int i =oIndex+1;i<5;i++)
            if(myFind(myCards,arr[i])){
                cout<<"YES"<<endl;
                return 0;
            } 
        cout<<"NO"<<endl;    
    }else{
        //不是顺子
        int cardNum = opponentCards.length();
        int 花色 = opponentCards[0]-'0';
        for(int i =花色+1;i<=9;i++){
            string temp="";
            for(int k =0;k<cardNum;k++)
                temp+=to_string(i);
            if(myCards.find(temp)!=-1){
                cout<<"YES"<<endl;
                return 0;
            }
        }
        cout<<"NO"<<endl;
    }
}
// 64 位输出请用 printf("%lld")

qd