It is easy to show that if you can only earn $p$ or $q$ coins, with $p$ and $q$ coprimes, the largest number of coins which cannot be earned is $pq-p-q$.
If we have two hourglasses that last $p$ and $q$ minutes respectively, the longest number of minutes which cannot be measured is smaller: for example, if they last 9 and 13 minutes it is possible to measure 17 minutes by starting them together, turning the first one when it's empty, and turning it again when the second one is empty. When the first hourglass becomes empty again, 17 minutes are elapsed.
Is there a formula which gives the longest number of minutes which cannot be measured?