You want something compatable. Pulley diameter doesn't have to be spot on, but pulley thickness and bearing shaft diameters need to match exactly. Shimano replacements list the compatable models printed on each package.
When installing, make sure they go in the right places. The guide pulley goes on top and the tension pulley on the bottom. They're usually marked, the bearings are different, and so is the lateral play.