public static void main ( String args [ ] ) {
  Scanner in ;
  PrintStream out ;
  in = new Scanner ( new BufferedInputStream ( System . in ) ) ;
  out = System . out ;
  try {
    in = new Scanner ( new FileInputStream ( "java.in" ) ) ;
    out = new PrintStream ( "java.out" ) ;
  }
  catch ( FileNotFoundException e ) {
  }
  int n = in . nextInt ( ) , k = in . nextInt ( ) , p = in . nextInt ( ) ;
  for ( int i = 1 ;
  i <= n ;
  i ++ ) a [ i ] = in . nextInt ( ) ;
  for ( int i = 1 ;
  i <= k ;
  i ++ ) b [ i ] = in . nextInt ( ) ;
  Arrays . sort ( a , 1 , n + 1 , new MyCom ( ) ) ;
  Arrays . sort ( b , 1 , k + 1 , new MyCom ( ) ) ;
  dp [ 0 ] [ 0 ] = 0 ;
  for ( int i = 1 ;
  i <= n ;
  i ++ ) {
    for ( int j = i ;
    j <= k ;
    j ++ ) {
      dp [ i ] [ j ] = Math . max ( dp [ i - 1 ] [ j - 1 ] , Math . abs ( a [ i ] - b [ j ] ) + Math . abs ( b [ j ] - p ) ) ;
      if ( j > i ) dp [ i ] [ j ] = Math . min ( dp [ i ] [ j ] , dp [ i ] [ j - 1 ] ) ;
    }
  }
  out . println ( dp [ n ] [ k ] ) ;
}

public static void main ( String args [ ] ) { Scanner in ; PrintStream out ; in = new Scanner ( new BufferedInputStream ( System . in ) ) ; out = System . out ; try { in = new Scanner ( new FileInputStream ( " java . in " ) ) ; out = new PrintStream ( " java . out " ) ; } catch ( FileNotFoundException e ) { } int n = in . nextInt ( ) , k = in . nextInt ( ) , p = in . nextInt ( ) ; for ( int i = 1 ; i <= n ; i ++ ) a [ i ] = in . nextInt ( ) ; for ( int i = 1 ; i <= k ; i ++ ) b [ i ] = in . nextInt ( ) ; Arrays . sort ( a , 1 , n + 1 , new MyCom ( ) ) ; Arrays . sort ( b , 1 , k + 1 , new MyCom ( ) ) ; dp [ 0 ] [ 0 ] = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = i ; j <= k ; j ++ ) { dp [ i ] [ j ] = Math . max ( dp [ i - 1 ] [ j - 1 ] , Math . abs ( a [ i ] - b [ j ] ) + Math . abs ( b [ j ] - p ) ) ; if ( j > i ) dp [ i ] [ j ] = Math . min ( dp [ i ] [ j ] , dp [ i ] [ j - 1 ] ) ; } } out . println ( dp [ n ] [ k ] ) ; }
(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))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier))) (expression_statement (assignment_expression left: (identifier) right: (object_creation_expression type: (type_identifier) arguments: (argument_list (object_creation_expression type: (type_identifier) arguments: (argument_list (field_access object: (identifier) field: (identifier)))))))) (expression_statement (assignment_expression left: (identifier) right: (field_access object: (identifier) field: (identifier)))) (try_statement body: (block (expression_statement (assignment_expression left: (identifier) right: (object_creation_expression type: (type_identifier) arguments: (argument_list (object_creation_expression type: (type_identifier) arguments: (argument_list (string_literal))))))) (expression_statement (assignment_expression left: (identifier) right: (object_creation_expression type: (type_identifier) arguments: (argument_list (string_literal)))))) (catch_clause (catch_formal_parameter (catch_type (type_identifier)) name: (identifier)) body: (block))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) 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: (identifier)) update: (update_expression (identifier)) body: (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (method_invocation object: (identifier) name: (identifier) 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: (identifier)) update: (update_expression (identifier)) body: (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (decimal_integer_literal) (binary_expression left: (identifier) right: (decimal_integer_literal)) (object_creation_expression type: (type_identifier) arguments: (argument_list))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (decimal_integer_literal) (binary_expression left: (identifier) right: (decimal_integer_literal)) (object_creation_expression type: (type_identifier) arguments: (argument_list))))) (expression_statement (assignment_expression left: (array_access array: (array_access array: (identifier) index: (decimal_integer_literal)) index: (decimal_integer_literal)) right: (decimal_integer_literal))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (identifier))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (expression_statement (assignment_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))) index: (binary_expression left: (identifier) right: (decimal_integer_literal))) (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (array_access array: (identifier) index: (identifier))))) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier))))))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (expression_statement (assignment_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)) (array_access array: (array_access array: (identifier) index: (identifier)) index: (binary_expression left: (identifier) right: (decimal_integer_literal)))))))))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)))))))