a,b,c,d;main(e){scanf("%d%d%d%*d%d%d",&a,&b,&c,&d,&e);a=!printf("%d",a+=fmin(c,e-fmax(d-b,0)));}