#include<stdio.h>
int main(){
    char hand[105],desk[10];
    while(scanf("%s",&hand)!=EOF){
        int nums1[10],len2=0;
        scanf("%s",&desk);
        for(int i=0;i<10;i++){
            nums1[i]=0;
        }
        for(int i=0;hand[i]!='\0';i++){
            int x=hand[i]-'0';
            nums1[x]++;
        }
        for(int i=0;desk[i]!='\0';i++){
            len2++;
        }
        if(len2==1){
            int flag=0,y=desk[0]-'0';
            for(int i=y+1;i<10;i++){
                if(nums1[i]!=0){
                    flag=1;
                    printf("YES");
                    break;
                }
            }
            if(flag==0) printf("NO");
        }
        if(len2==2){
            int flag=0,y=desk[0]-'0';
            for(int i=y+1;i<10;i++){
                if(nums1[i]>1){
                    flag=1;
                    printf("YES");
                    break;
                }
            }
            if(flag==0) printf("NO");
        }
        if(len2==3){
            int flag=0,y=desk[0]-'0';
            for(int i=y+1;i<10;i++){
                if(nums1[i]>2){
                    flag=1;
                    printf("YES");
                    break;
                }
            }
            if(flag==0) printf("NO");
        }
        if(len2==4){
            int flag=0,y=desk[0]-'0';
            for(int i=y+1;i<10;i++){
                if(nums1[i]>3){
                    flag=1;
                    printf("YES");
                    break;
                }
            }
            if(flag==0) printf("NO");
        }
        if(len2==5){
            int flag=0,y=desk[0]-'0';
            for(int i=y+1;i<6;i++){
                int count=0;
                for(int j=0;j<5;j++){
                    if(nums1[i+j]!=0) count++;
                }
                if(count==5){
                    flag=1;
                    printf("YES");
                    break;
                }
            }
            if(flag==0) printf("NO");
        }
    }
    return 0;
}