#define Z(i)for(X[i]=X[i-1]+1;X[i]<31;X[i]++) B[99],V[4],X[4],T=98,R,i,r;main(j){scanf("%d%d%d%d",V,V+1,V+2,V+3);R=T;Z(1)Z(2)Z(3){for(j=-1;++jB[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=fmin(R,r);}R=!printf("%d\n",R);}