x;a[9],b[9999],c[9],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=!puts(x?x>0?a:c:"-1");}