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