import java.util.Arrays; import java.util.HashSet; import java.util.LinkedList; import java.util.Scanner; import java.util.Set; public class Main { public static void main(String[] args){ Scanner sc = new Scanner(System.in); final int A = sc.nextInt(); final int B = sc.nextInt(); final int S = sc.nextInt(); if(S == 1){ // always A System.out.println(Math.abs(1 - A) + 1); }else{ final int SA_dist = Math.abs(A - S); final int SB_dist = Math.abs(B - S); if(SA_dist <= SB_dist){ // near A System.out.println(SA_dist + S); }else{ // near B if(A != 0){ System.out.println(SB_dist + Math.min(SA_dist + A, S - 1 + A)); }else{ System.out.println(SB_dist + S - 1 + 2); } //System.out.println(SB_dist + (A - 1) + S); } } } }