function processData(input) {
//Enter your code here
var hh = parseInt(input.substr(0, 2));
var mmss = input.substr(2, 6);
var pm = input.substr(8) === 'PM';
var is12 = hh === 12;
var res = (is12 ? (pm ? 12: 0):(pm ? hh + 12: hh));
console.log('' + (res < 10 ? '0': '') + res + mmss);
}
process.stdin.resume();
process.stdin.setEncoding("ascii");
_input = "";
process.stdin.on("data", function (input) {
_input += input;
});
process.stdin.on("end", function () {
processData(_input);
});