import datetime m,d,k=map(int,input().split()) t=datetime.date(2022,m,d) a="" for i in range(7): a+= str(t+datetime.timedelta(days=i)) if len(set(list(a[5:])))-1