A compound of formula: or a salt thereof, wherein: A is CH or N; B is phenyl, dihydroindenyl, dihydrobenzoxazinyl, dihydrobenzodioxinyl, chromenyl, tetrahydroisoquinolyl, tetrahydroquinolinyl, dihydroquinolyl, quinolyl, tetrahydroquinazolinyl, indolinyl, dihydrobenzothiazolyl, dihydrobenzimidazolyl, dihydrobenzoxazolyl, isoindolinyl, benzofuryl, benzothienyl, benzodioxolyl, indolyl, indazolyl, benzoimidazolyl, benzotriazolyl, benzisoxazolyl, benzoxazolyl, benzothiazolyl, benzoxadiazolyl, tetrahydrobenzothienyl, thienyl, thiazolyl, imidazolyl, pyrazolyl, thiadiazolyl or pyridyl; m is 1, 2, 3, or 4; E is phenyl, thienyl or pyrrolyl; when E is phenyl, n is 1, or 2; and when E is thienyl or pyrrolyl, n is 0, or 1; L is NR 5; one of X and Z is N and the other is CH; p is 0, 1, or 2; R 1 is C 1 -C 8 alkyl, halo, haloalkyl, haloalkoxy, alkoxyalkyl, -CN, oxo, -NO 2,-C NR b R b', -NR c C R c', -SO 2 NR b R b', -OR d, or -S q R f; R 2 is C 1 -C 8 alkyl, C 3 -C 8 cycloalkyl, thiomorpholinylalkyl, pyrrolidinylalkyl, morpholinylalkyl, haloalkyl, haloalkoxy, aminoalkyl, alkylaminoalkyl, dialkylaminoalkyl, hydroxyalkyl, alkoxyalkyl, silyloxyalkyl, -CN, -NO 2, -C OR a, -C NR b R b',-NR b R b', -OR d, -C R e or -S q R f; R 3 is C 1 -C 8 alkyl, halo, haloalkyl,-NR b R b' or-OR d R 5 is hydrogen; Y is O or S; q is 1 or 2 and each R a, R b, R b', R c, R c', R d, R e and R f is independently hydrogen, C 1 -C 8 alkyl, C 2 -C 8 alkenyl, C 2 -C 8 alkynyl, C 3 -C 8 cycloalkyl, phenyl, dihydroindenyl, morpholinyl, tetrahydropyranyl, piperidyl, pyrrolidinyl, thiomorpholinyl, phenylalkyl, thienylalkyl, pyridylalkyl, tetrahydropyranylalkyl, dihydroindenylalkyl, tetrahydrofurylalkyl, hydroxyalkyl, morpholinylalkyl, pyrrolidinylalkyl, dialkylaminoalkyl, piperidylalkyl, benzodioxolilalkyl, dihydrobenzodioxinylalkyl, C 3 -C 8 cycloalkylalkyl, haloalkyl or alkoxyalkyl. A is CH or N; B is phenyl, dihydroindenyl, dihydrobenzoxazinyl, dihydrobenzodioxinyl, chromenyl, tetrahydroisoquinolyl, tetrahydroquinolinyl, dihydroquinolyl, quinolyl, tetrahydroquinazolinyl, indolinyl, dihydrobenzothiazolyl, dihydrobenzimidazolyl, dihydrobenzoxazolyl, isoindolinyl, benzofuryl, benzothienyl, benzodioxolyl, indolyl, indazolyl, benzoimidazolyl, benzotriazolyl, benzisoxazolyl, benzoxazolyl, benzothiazolyl, benzoxadiazolyl, tetrahydrobenzothienyl, thienyl, thiazolyl, imidazolyl, pyrazolyl, thiadiazolyl or pyridyl; m is 1, 2, 3, or 4; E is phenyl, thienyl or pyrrolyl; when E is phenyl, n is 1, or 2; and when E is thienyl or pyrrolyl, n is 0, or 1; L is NR 5; one of X and Z is N and the other is CH; p is 0, 1, or 2; R 1 is C 1 -C 8 alkyl, halo, haloalkyl, haloalkoxy, alkoxyalkyl, -CN, oxo, -NO 2,-C NR b R b', -NR c C R c', -SO 2 NR b R b', -OR d, or -S q R f; R 2 is C 1 -C 8 alkyl, C 3 -C 8 cycloalkyl, thiomorpholinylalkyl, pyrrolidinylalkyl, morpholinylalkyl, haloalkyl, haloalkoxy, aminoalkyl, alkylaminoalkyl, dialkylaminoalkyl, hydroxyalkyl, alkoxyalkyl, silyloxyalkyl, -CN, -NO 2, -C OR a, -C NR b R b',-NR b R b', -OR d, -C R e or -S q R f; R 3 is C 1 -C 8 alkyl, halo, haloalkyl,-NR b R b' or-OR d R 5 is hydrogen; Y is O or S; q is 1 or 2 and each R a, R b, R b', R c, R c', R d, R e and R f is independently hydrogen, C 1 -C 8 alkyl, C 2 -C 8 alkenyl, C 2 -C 8 alkynyl, C 3 -C 8 cycloalkyl, phenyl, dihydroindenyl, morpholinyl, tetrahydropyranyl, piperidyl, pyrrolidinyl, thiomorpholinyl, phenylalkyl, thienylalkyl, pyridylalkyl, tetrahydropyranylalkyl, dihydroindenylalkyl, tetrahydrofurylalkyl, hydroxyalkyl, morpholinylalkyl, pyrrolidinylalkyl, dialkylaminoalkyl, piperidylalkyl, benzodioxolilalkyl, dihydrobenzodioxinylalkyl, C 3 -C 8 cycloalkylalkyl, haloalkyl or alkoxyalkyl.