num = [31,28,31,30,31,30,31,31,30,31,30,31]
try:
a,day = input().split()
a = int(a)
day = int(day)
if 1 <= a <= len(str(num)) and 1 <= day <= num[a-1]:
print(sum(num[a-1::]) - day)
else:
print("-1")
except:
num = [31,28,31,30,31,30,31,31,30,31,30,31]
try:
a,day = input().split()
a = int(a)
day = int(day)
if 1 <= a <= len(str(num)) and 1 <= day <= num[a-1]:
print(sum(num[a-1::]) - day)
else:
print("-1")
except:
print("-1")