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