#include <stdio.h>
int n, m, i, j, k, a, b, x, y;
int bad(int a, int b){
a += b/60, a %= 24, b %= 60;
x = a-a%10 + b/10;
y = a%10*10 + b%10;//交换后为x:y
if(x>23 || y>59) return 0;
printf("%d %d\n", a, b);
return 1;//合法则冲突
}
int main(){
scanf("%d%d", &n, &m);
for(i=0; i<60*24; i++){
if(bad(n, m+i)) break;
}//从接下来的24小时查找
return 0;
}