The present invention provides a compound of formula (I):wherein-X= is -CR7= or -N=,ring B is a substituted or unsubstituted carbocycle or a substituted or unsubstituted 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 and R4 are each independently hydrogen, halogen, substituted or unsubstituted alkyl or the like,R5 is hydrogen, substituted or unsubstituted alkyl or the like,each R6 is independently halogen, hydroxy, substituted or unsubstituted alkyl or the like, R7 is hydrogen, 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.