a,b,c,d;main(e){scanf("%d%d%d%*d%d%d",&a,&b,&c,&d,&e);d-=d>b?b:d;a=!printf("%d",a-d+(c+d