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