Problem G
Shattered Cake

A rectangular cake is transported via a truck to a
restaurant. On the way to the destination, the truck hits a
pothole, which shatters the cake into
At the destination, the damage is assessed, and the customer
decides to order a replacement cake of the same dimensions.
Unfortunately, the original order form was incompletely filled
and only the width
Input
The input consists of the following integers:
-
on the first line, the width
of the cake; -
on the second line, the number
of shattered pieces; -
on each of the next
lines, the width and length of each piece.
Limits
-
; -
; -
for each
, .
Output
The output should be the integer
Sample Input 1 | Sample Output 1 |
---|---|
4 7 2 3 1 4 1 2 1 2 2 2 2 2 2 1 |
6 |