#!/usr/bin/env python def read(): return map(int, raw_input().split()) def work((A, B, S)): if S == 1: print abs(S - A) + 1 elif abs(A - S) <= abs(B - S): print abs(A - S) + S elif B <= A: print abs(B - S) + min((abs(A - S) + 1) / 2 + A, A + S - 1) else: print abs(B - S) + min(abs(A - S) + A, A + S - 1) if __name__ == "__main__": work(read())