#define Z(i)for(X[i]=X[i-1]+1;X[i]<31;X[i]++) B[999],V[4],X[4],T,R,i,j,r;main(){ for(i=0;i<4;i++)scanf("%d",&V[i]),T+=V[i];R=T; Z(1)Z(2)Z(3){ for(j=-1;++j<=T;)B[j]=!j; for(i=4;--i>0;)for(j=X[i];j<=T;j++)if(B[j-X[i]]&&(!B[j]||B[j]>B[j-X[i]]))B[j]=B[j-X[i]]+1; for(i=r=0;i<4&&B[V[i]];)r+=B[V[i++]]-1; if(i>3&&R>r)R=r; } R=!printf("%d\n",R); }