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