f:A->B such that |f(A)|=k.

Without any restriction, the number of functions from A to B is m^n. By using inclusion and exclusion, I found the the number of onto functions as

(Sum from j=0 to j=m ) [(-1)^j]*C(m , j)*((m - j)^n) (Hopefully this is true) .

But i couldn't proceed any futher from here. Can you help me?