#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define all(x) (x).begin(),(x).end() #define rep(i,m,n) for(int i = m;i < n;++i) #define pb push_back #define fore(i,a) for(auto &i:a) #define rrep(i,m,n) for(int i = m;i >= n;--i) #define INF INT_MAX/2 using namespace std; using ll = long long; using R = double; const ll MOD = 1e9 + 7; const ll inf = 1LL << 50; struct edge { ll from; ll to; ll cost; }; int main() { int a, b, s; cin >> a >> b >> s; int xa = abs(a-s); int xb = abs(b-s); if (s == 1) { if (a == 0)cout << 2 << endl; else cout << a << endl; } else if (xa <= xb) { if (s < a)cout << a << endl; else cout << xa + s << endl; } else { if (s < a)cout << min(xb + s-1 + a, xb + xa + a) << endl; else if (a != 0) { cout << xb + (s - 1) + a << endl; } else { cout << xb + (s - 1) + 2 << endl; } } return 0; }