public static void main ( String [ ] args ) {
  Scanner sc = new Scanner ( System . in ) ;
  String s = sc . next ( ) ;
  int n = sc . nextInt ( ) ;
  int low = 0 ;
  int high = 100000 ;
  TreeMap < Character , Integer > map = new TreeMap < > ( ) ;
  for ( int i = 0 ;
  i < s . length ( ) ;
  i ++ ) {
    map . put ( s . charAt ( i ) , map . getOrDefault ( s . charAt ( i ) , 0 ) + 1 ) ;
  }
  int size = map . size ( ) ;
  if ( n < size ) {
    System . out . println ( "-1" ) ;
    return ;
  }
  while ( low < high ) {
    int mid = ( low + high ) / 2 ;
    int sum = 0 ;
    for ( Map . Entry < Character , Integer > entry : map . entrySet ( ) ) {
      sum += Math . ceil ( ( double ) entry . getValue ( ) / mid ) ;
    }
    if ( sum > n ) {
      low = mid + 1 ;
    }
    else {
      high = mid ;
    }
  }
  System . out . println ( high ) ;
  String ans = "" ;
  for ( Map . Entry < Character , Integer > entry : map . entrySet ( ) ) {
    char [ ] t = new char [ ( int ) Math . ceil ( ( double ) entry . getValue ( ) / high ) ] ;
    Arrays . fill ( t , entry . getKey ( ) ) ;
    String k = new String ( t ) ;
    ans += k ;
  }
  if ( ans . length ( ) < n ) {
    while ( ans . length ( ) < n ) {
      ans = ans + "a" ;
    }
  }
  System . out . println ( ans ) ;
}

public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; int n = sc . nextInt ( ) ; int low = 0 ; int high = 100000 ; TreeMap < Character , Integer > map = new TreeMap < > ( ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { map . put ( s . charAt ( i ) , map . getOrDefault ( s . charAt ( i ) , 0 ) + 1 ) ; } int size = map . size ( ) ; if ( n < size ) { System . out . println ( " - 1" ) ; return ; } while ( low < high ) { int mid = ( low + high ) / 2 ; int sum = 0 ; for ( Map . Entry < Character , Integer > entry : map . entrySet ( ) ) { sum += Math . ceil ( ( double ) entry . getValue ( ) / mid ) ; } if ( sum > n ) { low = mid + 1 ; } else { high = mid ; } } System . out . println ( high ) ; String ans = " " ; for ( Map . Entry < Character , Integer > entry : map . entrySet ( ) ) { char [ ] t = new char [ ( int ) Math . ceil ( ( double ) entry . getValue ( ) / high ) ] ; Arrays . fill ( t , entry . getKey ( ) ) ; String k = new String ( t ) ; ans += k ; } if ( ans . length ( ) < n ) { while ( ans . length ( ) < n ) { ans = ans + " a " ; } } System . out . println ( ans ) ; }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) 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: (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: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (local_variable_declaration type: (generic_type (type_identifier) (type_arguments (type_identifier) (type_identifier))) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (generic_type (type_identifier) (type_arguments)) arguments: (argument_list)))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) update: (update_expression (identifier)) body: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) (decimal_integer_literal))) right: (decimal_integer_literal))))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (block (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (string_literal)))) (return_statement))) (while_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) right: (decimal_integer_literal)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (enhanced_for_statement type: (generic_type (scoped_type_identifier (type_identifier) (type_identifier)) (type_arguments (type_identifier) (type_identifier))) name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) body: (block (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (cast_expression type: (floating_point_type) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) right: (identifier)))))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal))))) alternative: (block (expression_statement (assignment_expression left: (identifier) right: (identifier))))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (identifier)))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (string_literal))) (enhanced_for_statement type: (generic_type (scoped_type_identifier (type_identifier) (type_identifier)) (type_arguments (type_identifier) (type_identifier))) name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) body: (block (local_variable_declaration type: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (cast_expression type: (integral_type) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (cast_expression type: (floating_point_type) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) right: (identifier))))))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list (identifier))))) (expression_statement (assignment_expression left: (identifier) right: (identifier))))) (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (identifier))) consequence: (block (while_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (identifier))) body: (block (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (string_literal)))))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (identifier))))))