import java.util.Arrays; import java.util.PriorityQueue; import java.util.Scanner; class Main { public static void main(String[] args) { new Main().run(); } boolean check(long a,long b,long c) { return a>=0&&b>=0&&c>=0&&a!=b&&b!=c&&c!=a&&(b==Math.max(a, Math.max(b, c))||b==Math.min(a, Math.min(b, c))); } int max(long a,long b,long c,long d) { int ret=0; if(c>=b) { long q=(c+1-b+d-1)/d; ret+=q; c=Math.max(0,c-q*d); } if(a>=b) { long q=(a+1-b+d-1)/d; ret+=q; a=Math.max(0,a-q*d); } if(a==c) { ret++; c=Math.max(0, c-d); } if(check(a, b, c))return ret; else return -1; } int min(long a,long b,long c,long d) { int ret=0; if(a>c) { a^=c;c^=a;a^=c; } if(a==c) { ret++; a=Math.max(0, a-d); } if(a<=b) { long q=(b+1-a+d-1)/d; ret+=q; b=Math.max(0,b-q*d); } if(check(a, b, c))return ret; else return -1; } void run() { Scanner sc=new Scanner(System.in); long d=sc.nextLong(); long a=sc.nextLong(); long b=sc.nextLong(); long c=sc.nextLong(); if(d==0) { if(!check(a,b,c))System.out.println(-1); else System.out.println(0); return; } long INF=Long.MAX_VALUE/3; long ans=INF; if(min(a, b, c, d)!=-1)ans=Math.min(ans, min(a,b,c,d)); if(max(a, b, c, d)!=-1)ans=Math.min(ans, max(a,b,c,d)); System.out.println(ans==INF?-1:ans); } static void tr(Object... objects) { System.out.println(Arrays.deepToString(objects)); } }