问题
Bessie is a hungry cow. Each day, for dinner, if there is a haybale in the barn, she will eat one haybale. Farmer John does not want Bessie to starve, so some days he sends a delivery of haybales, which arrive in the morning (before dinner). In particular, on day
, Farmer John sends a delivery of
haybales (
,
).
Compute the total number of haybales Bessie will eat during the first
days.
INPUT FORMAT (input arrives from the terminal / stdin):
The first line contains
and
(
,
).
The next
lines each contain
and
. It is additionally guaranteed that
.
OUTPUT FORMAT (print output to the terminal / stdout):
Output the number of haybales that Bessie will eat during the first
days.
Note that the large size of integers involved in this problem may require the use of 64-bit integer data types (e.g., a "long long" in C/C++).
SAMPLE INPUT:
1 5
1 2
SAMPLE OUTPUT:
2
Two haybales arrive on the morning of day
. Bessie eats one haybale for dinner on day
and another haybale on day
. On days
, there are no more haybales for Bessie to eat. In total, Bessie eats
haybales during the first
days.
SAMPLE INPUT:
2 5
1 2
5 10
SAMPLE OUTPUT:
3
Two haybales arrive on the morning of day
. Bessie eats one haybale on days
and
. There are no haybales for Bessie to eat on days
and
. On the morning of day
,
haybales arrive. Bessie eats one haybale for dinner on day
. In total, Bessie eats
haybales during the first
days.
SAMPLE INPUT:
2 5
1 10
5 10
SAMPLE OUTPUT:
5
haybales arrive on the morning of day
. Bessie eats one haybale on days
. On the morning of day
, another
haybales arrive, meaning there are
haybales in the barn. For dinner on day
, Bessie eats another haybale. In total, Bessie eats
haybales during the first
days.
SCORING:
Inputs 4-7:
Inputs 8-13: No additional constraints.
请会的大蛇帮忙看看,万分感谢!
你这是哪一组别啊