#!/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 else: print abs(S - B) + A + min(B - 1, abs(A - B)) if __name__ == "__main__": work(read())