Skip to main content
LIVE CONTEST: Round #7 · Begin Marathon is live now! …
Problems
#859

~/algor $ cat problems/OaWd14LVqc3l

A half-price ticket

Medium 2000 ms 256 MB 66%
Share

A country has cities and one-way flights: flight goes from city to city , and its ticket costs soums. You have one discount coupon: used on one flight, it makes that flight's ticket cost soums. What is the smallest amount needed to fly from city to city ? If it is impossible, print .

Four cities and flights with prices: the cheapest route is 1 → 3 → 4 with the coupon on the flight 3 → 4, 6 instead of 12

Input

The first line contains two positive integers: and . Line of the next lines contains three positive integers: , and .

Output

One integer — the smallest cost or .

Note



,

Examples

Input #1
4 5
1 2 8
2 4 6
1 3 3
3 4 12
2 3 1
Output #1
9
Input #2
3 1
2 3 5
Output #2
-1

Sign in to submit a solution

Signing up is free and takes a minute.