The present invention provides a compound of formula (I):wherein ring B is substituted or unsubstituted carbocycle or heterocycle,R1 is substituted or unsubstituted alkyl or the like,R2a and R2b are each independently hydrogen, substituted or unsubstituted alkyl or the like,R3, R4a and R4b are each independently hydrogen, halogen, substituted or unsubstituted alkyl or the like, a dashed line represents a presence or absence of a bond,R5 is hydrogen, substituted or unsubstituted alkyl or the like,R6 is halogen, hydroxy, substituted or unsubstituted alkyl or the like,p is an integer of 0 to 3,or a pharmaceutically acceptable salt thereof which has an effect of inhibiting amyloid β production, especially an effect of inhibiting BACE1, and which is useful as a therapeutic or prophylactic agent for diseases induced by production, secretion and/or deposition of amyloid β proteins.