public static void main(String[] args) {
Scanner in=new Scanner(System.in);
long n=in.nextLong();
long res=0;
long a=in.nextLong(),b=in.nextLong(),c=in.nextLong();
c=Math.min(c, n);
if(a>1) {
if(c<n) {
res=n+n-1;
}else {
res=2*n+b-a;
}
}else{
if(c<n) {
res=n+c+n-1;
}else {
res=3*n+b-2;
}
}
System.out.println(res);
in.close();
}