A, B, C, D = map(int, input().split()) d = 31 - A + B eng = True if d - C >= 0 else False jpn = True if d - D >= 0 else False if eng: print(1) elif jpn: print(2) else: print(3)