A nonreflecting boundary condition for discrete acoustic and elastic wave equations