Your problem is
$$\max U(z_1,...,z_n) $$
$$s.t. \sum p_iz_i \leq I$$
$$s.t. \sum z_i = X, \;\;\; z_i\in N$$
So you have an additional linear constraint, but also, as noted in a comment, the $z_i\in N$ constraint makes this an optimization problem where the decision variables are discrete (specifically integers), meaning that, formally speaking, you don't get to have derivatives.
In practice, many discrete optimization problems are attacked by "pretending" that we can calculate derivatives, (so form the Lagrangian with the two constraints, obtain Karush-Kuhn-Tucker conditions, etc), obtain the maximizer vector in this way, and then check what happens as we round up or down its elements so that they become integers.
You also need to check the budget constraint is not violated by these roundings, and allow only those combinations that don't. Here the budget constraint as inequality is important because the permissible maximizer vector of $z_i$'s most likely won't fully exhaust the budget.
See here for some introductory bits on Integer Programming.