public static void main ( String [ ] args ) throws IOException {
  BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ;
  StringTokenizer stt = new StringTokenizer ( br . readLine ( ) ) ;
  int h = Integer . parseInt ( stt . nextToken ( ) ) ;
  int w = Integer . parseInt ( stt . nextToken ( ) ) ;
  char c = stt . nextToken ( ) . charAt ( 0 ) ;
  char [ ] [ ] arr = new char [ h ] [ w ] ;
  for ( int i = 0 ;
  i < h ;
  i ++ ) {
    arr [ i ] = br . readLine ( ) . toCharArray ( ) ;
  }
  TreeSet < Character > set = new TreeSet < > ( ) ;
  for ( int i = 0 ;
  i < h ;
  ++ i ) {
    int index = String . valueOf ( arr [ i ] ) . indexOf ( c ) ;
    if ( index >= 0 ) {
      for ( int j = index ;
      j < w ;
      ++ j ) {
        if ( arr [ i ] [ j ] == c ) {
          if ( i > 0 ) {
            set . add ( arr [ i - 1 ] [ j ] ) ;
          }
          if ( i < h - 1 ) {
            set . add ( arr [ i + 1 ] [ j ] ) ;
          }
          if ( j > 0 ) {
            set . add ( arr [ i ] [ j - 1 ] ) ;
          }
          if ( j < w - 1 ) {
            set . add ( arr [ i ] [ j + 1 ] ) ;
          }
        }
        else {
          break ;
        }
      }
    }
  }
  set . remove ( '.' ) ;
  set . remove ( c ) ;
  System . out . println ( set . size ( ) ) ;
}

public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringTokenizer stt = new StringTokenizer ( br . readLine ( ) ) ; int h = Integer . parseInt ( stt . nextToken ( ) ) ; int w = Integer . parseInt ( stt . nextToken ( ) ) ; char c = stt . nextToken ( ) . charAt ( 0 ) ; char [ ] [ ] arr = new char [ h ] [ w ] ; for ( int i = 0 ; i < h ; i ++ ) { arr [ i ] = br . readLine ( ) . toCharArray ( ) ; } TreeSet < Character > set = new TreeSet < > ( ) ; for ( int i = 0 ; i < h ; ++ i ) { int index = String . valueOf ( arr [ i ] ) . indexOf ( c ) ; if ( index >= 0 ) { for ( int j = index ; j < w ; ++ j ) { if ( arr [ i ] [ j ] == c ) { if ( i > 0 ) { set . add ( arr [ i - 1 ] [ j ] ) ; } if ( i < h - 1 ) { set . add ( arr [ i + 1 ] [ j ] ) ; } if ( j > 0 ) { set . add ( arr [ i ] [ j - 1 ] ) ; } if ( j < w - 1 ) { set . add ( arr [ i ] [ j + 1 ] ) ; } } else { break ; } } } } set . remove ( ' . ' ) ; set . remove ( c ) ; System . out . println ( set . size ( ) ) ; }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) (throws (type_identifier)) body: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list (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: (object_creation_expression type: (type_identifier) arguments: (argument_list (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 (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 (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) name: (identifier) arguments: (argument_list (decimal_integer_literal))))) (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 (identifier)) dimensions: (dimensions_expr (identifier))))) (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 (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) name: (identifier) arguments: (argument_list)))))) (local_variable_declaration type: (generic_type (type_identifier) (type_arguments (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: (identifier)) update: (update_expression (identifier)) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)))) name: (identifier) arguments: (argument_list (identifier))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (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 (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)) right: (identifier))) consequence: (block (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (block (expression_statement (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: (identifier))))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) consequence: (block (expression_statement (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: (identifier))))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (array_access array: (identifier) index: (identifier)) index: (binary_expression left: (identifier) right: (decimal_integer_literal)))))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) consequence: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (array_access array: (identifier) index: (identifier)) index: (binary_expression left: (identifier) right: (decimal_integer_literal))))))))) alternative: (block (break_statement))))))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (character_literal)))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))))