"""
The Unix command cal produces a calendar as

$ cal 8 2014
     August 2014    
Su Mo Tu We Th Fr Sa
                1  2
 3  4  5  6  7  8  9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31

Assume that this output of cal 8 2014 is on file cal.txt.
Design an algorithm that, given a number between 1 and 31,
returns the day of the week.
For example, if the given number is 8, then Fr is returned.
"""
DAYS = { 0:'Su', 1:'Mo', 2:'Tu', 3:'We', 4:'Th', 5:'Fr', 6:'Sa' }
DAYRAW = raw_input('give a number between 1 and 31 : ')
DAY = int(DAYRAW)
CAL = open('cal.txt', 'r')
CNT = 0
DONE = False
while not DONE:
    LINE = CAL.readline()
    if LINE == '':
        break
    if CNT > 1:
        PRT = LINE[0:2]
        if PRT != '  ':
            NUM = int(PRT)
            if NUM == DAY:
                print DAYS[0]
                DONE = True
        if DONE:
            break
        for k in range(6):
            PRT = LINE[2+3*k:2+3*k+3]
            if PRT != '   ':
                NUM = int(PRT)
                if NUM == DAY:
                    print DAYS[k+1]
                    DONE = True
    CNT = CNT + 1
