public static void main ( String args [ ] ) {
  Scanner scanner = new Scanner ( System . in ) ;
  int format = scanner . nextInt ( ) ;
  String s = scanner . next ( ) ;
  int a = s . charAt ( 0 ) - '0' ;
  int b = s . charAt ( 1 ) - '0' ;
  int c = s . charAt ( 3 ) - '0' ;
  int d = s . charAt ( 4 ) - '0' ;
  if ( c > 5 ) c = 0 ;
  if ( format == 24 && a > 2 ) a = 0 ;
  if ( format == 24 && a == 2 && b >= 4 ) a = 0 ;
  if ( format == 12 && a == 0 && b == 0 ) b = 1 ;
  else if ( format == 12 && a == 1 && b > 2 ) b = 1 ;
  else if ( format == 12 && a > 1 && b > 2 ) a = 0 ;
  else if ( format == 12 && a > 1 ) a = 1 ;
  System . out . println ( a + "" + b + ":" + c + "" + d ) ;
}

public static void main ( String args [ ] ) { Scanner scanner = new Scanner ( System . in ) ; int format = scanner . nextInt ( ) ; String s = scanner . next ( ) ; int a = s . charAt ( 0 ) - '0' ; int b = s . charAt ( 1 ) - '0' ; int c = s . charAt ( 3 ) - '0' ; int d = s . charAt ( 4 ) - '0' ; if ( c > 5 ) c = 0 ; if ( format == 24 && a > 2 ) a = 0 ; if ( format == 24 && a == 2 && b >= 4 ) a = 0 ; if ( format == 12 && a == 0 && b == 0 ) b = 1 ; else if ( format == 12 && a == 1 && b > 2 ) b = 1 ; else if ( format == 12 && a > 1 && b > 2 ) a = 0 ; else if ( format == 12 && a > 1 ) a = 1 ; System . out . println ( a + " " + b + " : " + c + " " + d ) ; }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (type_identifier) name: (identifier) dimensions: (dimensions))) body: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list (field_access object: (identifier) field: (identifier)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal))) right: (character_literal)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal))) right: (character_literal)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal))) right: (character_literal)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal))) right: (character_literal)))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal)))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) consequence: (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal)))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) consequence: (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal)))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) consequence: (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) consequence: (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) consequence: (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) consequence: (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (binary_expression left: (binary_expression left: (binary_expression left: (binary_expression left: (binary_expression left: (binary_expression left: (identifier) right: (string_literal)) right: (identifier)) right: (string_literal)) right: (identifier)) right: (string_literal)) right: (identifier)))))))