The present invention provides a compound of formula (I): wherein -X= is -CR 7 = or -N=, ring B is a substituted or unsubstituted carbocycle or a substituted or unsubstituted heterocycle, R 1 is substituted or unsubstituted alkyl or the like, R 2a and R 2b are each independently hydrogen, substituted or unsubstituted alkyl or the like, R 3 and R 4 are each independently hydrogen, halogen, substituted or unsubstituted alkyl or the like, R 5 is hydrogen, substituted or unsubstituted alkyl or the like, each R 6 is independently halogen, hydroxy, substituted or unsubstituted alkyl or the like, R 7 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.