x;a[9],b[999],c[9],d[999];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");}