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