#include using namespace std; typedef pair P; typedef pair> PP; typedef long long ll; const double EPS = 1e-8; const int INF = 1e9; const int MOD = 1e9+7; int dy[] = {0,1,0,-1}; int dx[] = {1,0,-1,0}; int main(void) { int a,b,s; cin >> a >> b >> s; if(abs(a-s) <= abs(b-s) || s == 1){ cout << abs(a-s) + s << endl; }else{ int ans = abs(s-b); //Aが地下にある可能性を考慮してない if(b > a){ ans += s; if(a == 0){ s += 1; } }else{ int BtoA = abs(b-a); int Ato1 = a-1; int Bto1 = b-1; if(BtoA < Ato1){ ans += BtoA + a; }else{ ans += Bto1 + a; } } cout << ans << endl; } return 0; }