#include<bits/stdc++.h>
using namespace std;
int D[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
bool checkLeapyear(int y){
return y%400==0||y%4==0&&y%100!=0;
}
bool checkABABBABAstyle(string s){
if(s[0]==s[2]&&s[0]==s[5]&&s[0]==s[7]&&s[1]==s[3]&&s[1]==s[4]&&s[1]==s[6]) return true;
return false;
}
int main(){
string S, ans1="", ans2="";
string s,t,year;
int y,m,d;
cin>>S;
//取字符串0-3的元素
year=S.substr(0,4);
//stoi把字符串转换为数值
//且使用stoi必须在要赋值int的地方用
//例如下面 int i 要int型,所以就在这里对year用stoi
for(int i = stoi(year); ans1== "" || ans2== ""; i++){
//i初值为输入数据的年
//找到ans1和ans2后结束循环
//to_string转化数值为字符串
s = to_string(i) , t = to_string(i);//s为当前枚举的年
//reverse 直接用就好不需要t=reverse()
reverse(t.begin(),t.end());//求年的逆
s+=t;//拼接出年月日
if(s<=S) continue;//构造出的s若小于初始日期,不计
//下面第一个sunstr中指第0位开始取四位
y = stoi(s.substr(0,4)), m = stoi(s.substr(4,2)), d = stoi(s.substr(6,2));
if(checkLeapyear(y)) D[2] = 29;
if(m<1||m>12) continue;
if(d<1||d>D[m]) continue;
if(ans1=="") ans1 = s;
if(checkABABBABAstyle(s) && ans2 == "") ans2 = s;
}
cout<<ans1<<endl<<ans2;
return 0;
}