How does one determine the relative basicity of a nitrogen in a molecule?
Use a combination of 


the exclusion principle: sort out the unlikely centres with low electron density and 
paper work to figure out those nitrogen atoms for which the additional positive charge can be distributed over a larger part of the molecule without moving the proton.




In the case of caffeine (1) the amide and the imide are rather unlikely centres for protonation! You have probably already ruled out the amide nitrogen in the benzamide case (your second molecule) in favour of the aniline site.

From an initial number of four possible centres in 1, only two remain.

Now, let's see whether the positive charge resulting from protonation can be stabilized.



This looks fair, but creates a quarternary ammonium ion for which no obvious charge distribution seems to be available.

Let's examine the last possibility:



Would you agree that this looks much more promising?