a,b,c,d,s,t;main(){scanf("%d%d%d%d",&d,&a,&b,&c);if((ab&c>b)&&a-c&&puts("0")||!d&&puts("-1"))exit(0);a>c?a^=c^=a^=c:a==c?s++,a=a