a,b,c,d = map(int,input().split()) t = b + (31 - a + 1) if c + 1<= t: print(1) elif d + 1<= t: print(2) else: print(3)