#include #include #include #include #include #include #include #include #include #include #include #include typedef long long ll; using namespace std; const int mod = 1000000007; const int INF = (int)1e9; const ll LLINF = (ll)2e18; const double PI = 3.1415926536; const int SIZE = 1000; int main(){ int a,b,s,ans; int d_a,d_b; scanf("%d%d%d",&a,&b,&s); d_a = abs(s-a); d_b = abs(s-b); if(d_a <= d_b || s==1){ ans = d_a + s; }else{ ans = d_b + min(d_a + a,s-1 + abs(a-1) + 1); } printf("%d\n",ans); return 0; }