Max flow with priorities
First, build an algorithm to solve the  following problem:

Given a threshold $t$ and a flow graph $G$, find the solution that maximizes $N_2$, subject to the requirement that $N_1 \ge t$.

That problem  can be solved using algorithms for minimum cost circulation, which is a generalization of max flow where we can also have lower bounds on certain edges.  (You'll set the cost of all edges out of the source to 1 and the cost of all other edges to 0, as you don't need different costs.)

Then, do binary search on $t$ to find the largest $t$ for which a solution exists.



How do you solve the problem above?  We need to modify the graph.  Instead of adding a single source vertex $s$, we'll add three vertices $s,s_1,s_2$.  Add an edge $s \to s_1$ with lower bound on capacity of $t$.  Add an edge $s \to s_2$ with lower bound 0.   Add edges $s_1 \to a_i$ for each $i$ where $p(a_i)=1$, and $s_2 \to a_i$ for each $i$ where $p(a_i)=2$.  All edges other than the $s \to s_1$ edge have lower bound on capacity of 0.  Now any valid flow for this problem that respects the lower bounds will satisfy $N_1 \ge t$.