#include<stdio.h>
int main()
{
int a,b,c;
int day1,day;
char ch1,ch2;
scanf("%d %c %d %c %d",&a,&ch1,&b,&ch2,&c);
switch (b)
{
case 1 :
day1=0;
break;
case 2 :
day1=31;
break;
case 3 :
day1=59;
break;
case 4 :
day1=90;
break;
case 5 :
day1=120;
break;
case 6 :
day1=151;
break;
case 7 :
day1=181;
break;
case 8 :
day1=212;
break;
case 9 :
day1=243;
break;
case 10 :
day1=273;
break;
case 11 :
day1=304;
break;
case 12 :
day1=334;
}
day=day1+c;
if(a%4==0&&a%100!=0)
{
day++;
}
printf("%dth",day);
return 0;
}