We can also arrive at the equation by counting degrees of freedom directly instead of recalling the formula.
Each unconnected rigid link moving in a plane has 3 degrees of freedom, two for translation and one for rotation. With $l$ links, and one of them fixed as the frame, the degrees of freedom available before adding any joints is $3(l-1)$.
Every lower pair, such as a pin joint or a sliding joint, removes 2 degrees of freedom because it only allows one relative motion between the two links it connects. With $j$ such joints, we subtract $2j$.
Every higher pair, such as a cam and follower or two gear teeth in contact, removes only 1 degree of freedom because it allows two relative motions, sliding and rolling, between the links. With $h$ such pairs, we subtract $h$.
Putting this together gives $n = 3(l-1) - 2j - h$, the same as option 1.
\[\boxed{n = 3(l-1) - 2j - h}\]