import java.util.Scanner; public class No126 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int A = sc.nextInt(); int B = sc.nextInt(); int S = sc.nextInt(); int l = 0; //距離 if(S == 0) { System.out.println(0); return; } if(S == 1) { System.out.println(Math.abs(A-S) + S); return; } if(Math.abs(A-S) <= Math.abs(B-S)) { System.out.println(Math.abs(A-S) + S); }else if(Math.abs(S-1) <= Math.abs(S-A)) { System.out.println(Math.abs(S-B)+S-1+A); } else { System.out.println(Math.abs(A-B)+A); } } }