x;a[99],b[9999],c[99],d[9999];main(){scanf("%s%s%*s%s%s",a,b,c,d);x=strlen(b)-strlen(d);x=x?x:strcmp(b,d);x=!printf("%s",x?x>0?a:c:"-1");}