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=a0&&printf("%d",s)||!a&!c|!d&&puts("-1"))exit(0);t=(c-b)/d+1;t=a|t*d