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