import java.util.*; public class Exercise126{ 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 ans = 0; if(a == b || s == 1 || s == a || Math.abs(s - a) <= Math.abs(s - b)){ ans = Math.abs(s - a) + (s - 0); }else{ if(a < b){ if(a > 0){ ans = Math.abs(s - b) + (s - a) + (a - 0); }else{ ans = Math.abs(s - b) + (s - 1) + 2; } }else{ if(s > a / 2){ ans = Math.abs(s - b) + (a - s) + (a - 0); }else{ ans = Math.abs(s - b) + (s - 1) + (a - 0); } } } System.out.println(ans); } }