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)