def run(year): if (year % 400 == 0): return True elif (year % 100 == 0): return False elif (year % 4 == 0): return True else: return False ms = [0, 31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] y, m, d = map(int, input().split()) ms[2] = 29 if run(y) else 28 ans = 0 for i in range(1, m): ans += ms[i] print(ans+d)