#include <stdio.h>
int main()
{
int a,b;
scanf("%d:%d",&a,&b);
const int h_to_m = 60 ;
const int d_to_h = 24 ;
int temp_time = a * h_to_m + b ;
if( temp_time == 0 || temp_time == (h_to_m * d_to_h) ){
printf("0:0 AM\n");
}
else{
if(temp_time != (h_to_m * d_to_h) / 2){
if(a > (d_to_h/2)){
printf("%d:%d PM\n", a - d_to_h/2, b);
}
else if(a == (d_to_h/2)){
printf("%d:%d PM\n", a, b);
}
else{
printf("%d:%d AM\n", a, b);
}
}
else{
printf("%d:%d PM\n", a, b);
}
}
return 0;
}