#include <bits/stdc++.h>
using namespace std;
int a,b,c;
char s;
int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
bool cheak1(int x)
{
if((x%4==0&&x/100!=0)||(x%400==0))
return true;
else
return false;
}
bool cheak2(int aa,int bb,int cc)
{
int fl=aa%100;
if(fl==a&&bb==b&&cc==c)
return true;
if(fl==c&&bb==a&&cc==b)
return true;
if(fl==c&&bb==b&&cc==a)
return true;
return false;
}
int main()
{
cin>>a>>s>>b>>s>>c;
for(int i=1960;i<=2059;i++)
{
if(cheak1(i))
d[2]++;
for(int j=1;j<=12;j++)
{
for(int k=1;k<=d[j];k++)
{
if(cheak2(i,j,k))
{
cout<<i<<"-";
if(j<=9)
cout<<"0";
cout<<j<<"-";
if(k<=9)
cout<<"0";
cout<<k<<endl;
}
}
}
}
return 0;
}