A compound of the formula: wherein: each R a is independently H, halo, C 1-6 alkyl, C 1-6 haloalkyl, C 3-6 cycloalkyl, OH, -O-C 1-6 alkyl, -O-C 1-6 haloalkyl, -O-C 3-6 cycloalkyl, NH 2, -NH-C 1-6 alkyl, -NH-C 1-6 haloalkyl, -NH-C 3-6 cycloalkyl, -S-C 1-6 alkyl, -S-C 1-6 haloalkyl, -S-C 3-6 cycloalkyl, CN, or NO 2; m is 0, 1, 2, 3, or 4; one of A 1 and A 2 is N and the other is NR 1, wherein R 1 is H, OH, C 1-6 alkyl, C 1-6 haloalkyl, or C 3-6 cycloalkyl; X is a bond, -(CH 2) p -, -NR 2 -, -O-, or -S-, wherein p is 0 or 1, and R 2 is H or C 1-3 alkyl; each R b is independently H, halo, C 1-6 alkyl, C 1-6 haloalkyl, C 3-6 cycloalkyl, C 2-6 alkenyl, C 2-6 alkynyl, -(CH 2) q -OR 3, -(CH 2) q -NR 3 R 4, -(CH 2) q -SR 3, -(CH 2) q -NO 2, -(CH 2) q -CONHOH, -(CH 2) q -CN, -(CH 2) q -COR 3, -(CH 2) q -CO 2 R 3, -(CH 2) q -CONR 3 R 4, -(CH 2) q -tetrazole, -(CH 2) q -CH=CH-CN, -(CH 2) q -CH=CH-CO 2 R 3, -(CH 2) q -CH=CH-CONR 3 R 4, -(CH 2) q -CH=CH-tetrazole, -(CH 2) q -NHCOR 3, -(CH 2) q -NHCO 2 R 3, -(CH 2) q -CONHSO 2 R 3, -(CH 2) q -NHSO 2 R 3, -(CH 2) q -C≡C-CN, -(CH 2) q -C≡C-CO 2 R 3, -(CH 2) q - C≡C-CONR 3 R 4, -(CH 2) q -C≡C-tetrazole, -(CH 2) q -SOR 5, -(CH 2) q -SO 2 R 5, or -(CH 2) r - (OR 3) 2, wherein R 3 and R 4 are independently H, C 1-6 alkyl, C 1-6 haloalkyl, or C 3-6 cycloalkyl; or taken together with the nitrogen atom to which they are attached form a mono-cyclic ring such as imidazole, pyrrolidine, piperidine, morpholine, piperazine and homopiperazine; R 5 is C 1-6 alkyl, C 1-6 haloalkyl, or C 3-6 cycloalkyl; q is 0, 1, 2, 3, or 4; and r is 1, 2, 3, or 4; n is 0, 1, 2, 3, 4, or 5; or a pharmaceutically acceptable salt or hydrate thereof. each R a is independently H, halo, C 1-6 alkyl, C 1-6 haloalkyl, C 3-6 cycloalkyl, OH, -O-C 1-6 alkyl, -O-C 1-6 haloalkyl, -O-C 3-6 cycloalkyl, NH 2, -NH-C 1-6 alkyl, -NH-C 1-6 haloalkyl, -NH-C 3-6 cycloalkyl, -S-C 1-6 alkyl, -S-C 1-6 haloalkyl, -S-C 3-6 cycloalkyl, CN, or NO 2; m is 0, 1, 2, 3, or 4; one of A 1 and A 2 is N and the other is NR 1, wherein R 1 is H, OH, C 1-6 alkyl, C 1-6 haloalkyl, or C 3-6 cycloalkyl; X is a bond, -(CH 2) p -, -NR 2 -, -O-, or -S-, wherein p is 0 or 1, and R 2 is H or C 1-3 alkyl; each R b is independently H, halo, C 1-6 alkyl, C 1-6 haloalkyl, C 3-6 cycloalkyl, C 2-6 alkenyl, C 2-6 alkynyl, -(CH 2) q -OR 3, -(CH 2) q -NR 3 R 4, -(CH 2) q -SR 3, -(CH 2) q -NO 2, -(CH 2) q -CONHOH, -(CH 2) q -CN, -(CH 2) q -COR 3, -(CH 2) q -CO 2 R 3, -(CH 2) q -CONR 3 R 4, -(CH 2) q -tetrazole, -(CH 2) q -CH=CH-CN, -(CH 2) q -CH=CH-CO 2 R 3, -(CH 2) q -CH=CH-CONR 3 R 4, -(CH 2) q -CH=CH-tetrazole, -(CH 2) q -NHCOR 3, -(CH 2) q -NHCO 2 R 3, -(CH 2) q -CONHSO 2 R 3, -(CH 2) q -NHSO 2 R 3, -(CH 2) q -C≡C-CN, -(CH 2) q -C≡C-CO 2 R 3, -(CH 2) q - C≡C-CONR 3 R 4, -(CH 2) q -C≡C-tetrazole, -(CH 2) q -SOR 5, -(CH 2) q -SO 2 R 5, or -(CH 2) r - (OR 3) 2, wherein R 3 and R 4 are independently H, C 1-6 alkyl, C 1-6 haloalkyl, or C 3-6 cycloalkyl; or taken together with the nitrogen atom to which they are attached form a mono-cyclic ring such as imidazole, pyrrolidine, piperidine, morpholine, piperazine and homopiperazine; R 5 is C 1-6 alkyl, C 1-6 haloalkyl, or C 3-6 cycloalkyl; q is 0, 1, 2, 3, or 4; and r is 1, 2, 3, or 4; n is 0, 1, 2, 3, 4, or 5; or a pharmaceutically acceptable salt or hydrate thereof.