public static void main ( String [ ] args ) {
  Scanner in = new Scanner ( System . in ) ;
  String s1 = in . next ( ) , s2 = in . next ( ) , s3 = in . next ( ) ;
  in . close ( ) ;
  char c1 = s1 . charAt ( 1 ) , c2 = s2 . charAt ( 1 ) , c3 = s3 . charAt ( 1 ) ;
  int i1 = Integer . valueOf ( s1 . substring ( 0 , 1 ) ) , i2 = Integer . valueOf ( s2 . substring ( 0 , 1 ) ) , i3 = Integer . valueOf ( s3 . substring ( 0 , 1 ) ) , a [ ] = new int [ ] {
    i1 , i2 , i3 };
    Arrays . sort ( a ) ;
    if ( s1 . equals ( s2 ) && s1 . equals ( s3 ) || ( a [ 2 ] - a [ 1 ] == 1 && a [ 1 ] - a [ 0 ] == 1 && c1 == c2 && c1 == c3 ) ) {
      System . out . println ( 0 ) ;
    }
    else if ( s1 . equals ( s2 ) || s1 . equals ( s3 ) || s2 . equals ( s3 ) || ( c1 == c2 && Math . abs ( i1 - i2 ) < 3 ) || ( c1 == c3 && Math . abs ( i1 - i3 ) < 3 ) || ( c2 == c3 && Math . abs ( i2 - i3 ) < 3 ) ) {
      System . out . println ( 1 ) ;
    }
    else {
      System . out . println ( 2 ) ;
    }
  }
  
public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; String s1 = in . next ( ) , s2 = in . next ( ) , s3 = in . next ( ) ; in . close ( ) ; char c1 = s1 . charAt ( 1 ) , c2 = s2 . charAt ( 1 ) , c3 = s3 . charAt ( 1 ) ; int i1 = Integer . valueOf ( s1 . substring ( 0 , 1 ) ) , i2 = Integer . valueOf ( s2 . substring ( 0 , 1 ) ) , i3 = Integer . valueOf ( s3 . substring ( 0 , 1 ) ) , a [ ] = new int [ ] { i1 , i2 , i3 } ; Arrays . sort ( a ) ; if ( s1 . equals ( s2 ) && s1 . equals ( s3 ) || ( a [ 2 ] - a [ 1 ] == 1 && a [ 1 ] - a [ 0 ] == 1 && c1 == c2 && c1 == c3 ) ) { System . out . println ( 0 ) ; } else if ( s1 . equals ( s2 ) || s1 . equals ( s3 ) || s2 . equals ( s3 ) || ( c1 == c2 && Math . abs ( i1 - i2 ) < 3 ) || ( c1 == c3 && Math . abs ( i1 - i3 ) < 3 ) || ( c2 == c3 && Math . abs ( i2 - i3 ) < 3 ) ) { System . out . println ( 1 ) ; } else { System . out . println ( 2 ) ; } }
(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))) 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)))) (expression_statement (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 (decimal_integer_literal)))) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal)))) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal) (decimal_integer_literal)))))) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal) (decimal_integer_literal)))))) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal) (decimal_integer_literal)))))) declarator: (variable_declarator name: (identifier) dimensions: (dimensions) value: (array_creation_expression type: (integral_type) dimensions: (dimensions) value: (array_initializer (identifier) (identifier) (identifier))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) right: (parenthesized_expression (binary_expression left: (binary_expression left: (binary_expression left: (binary_expression left: (binary_expression left: (array_access array: (identifier) index: (decimal_integer_literal)) right: (array_access array: (identifier) index: (decimal_integer_literal))) right: (decimal_integer_literal)) right: (binary_expression left: (binary_expression left: (array_access array: (identifier) index: (decimal_integer_literal)) right: (array_access array: (identifier) index: (decimal_integer_literal))) right: (decimal_integer_literal))) right: (binary_expression left: (identifier) right: (identifier))) right: (binary_expression left: (identifier) right: (identifier)))))) consequence: (block (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (decimal_integer_literal))))) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (binary_expression left: (binary_expression left: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) right: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (identifier)))) right: (decimal_integer_literal))))) right: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (identifier)))) right: (decimal_integer_literal))))) right: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (identifier)))) right: (decimal_integer_literal)))))) consequence: (block (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (decimal_integer_literal))))) alternative: (block (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (decimal_integer_literal)))))))))