#D4024. Dimension travel

    ID: 3346 Type: Default 1000ms 268MiB

Dimension travel

Dimension travel

problem

Dimension exists from 1 1 dimension to N N dimension. AOR Ika can move between dimensions. Specifically, when AOR Ika is in the i i dimension, she can move freely to the j j dimension (i>j i> j ), but in the k k dimension (i<k i <k ). You need to use magic to move to.

AOR Ika can use M M types of magic and is numbered 1,2, dots,M 1, 2, \ dots, M . The i i th magic allows you to move from the ai a_i dimension to the bi b_i dimension. This can only be used when you are in the ai a_i dimension.

When you go to the i i dimension, you will receive a dimension-specific "curse of dimensionality". AOR Ika takes di d_i damage due to the "curse of dimensionality" of the i i dimension. If you receive the "curse of dimensionality" of the i i dimension, you will not receive the "curse of dimensionality" of the j j dimension (i>j i> j ) forever.

Find the minimum total damage inflicted when AOR Ika moves from the s s dimension to the t t dimension. However, AOR Ika-chan has already received the "curse of dimensionality" of the s s dimension, and we will not consider the damage. Also, AOR Ika is guaranteed to be able to go to the t t dimension.

output

Output the minimum value of the total damage received by AOR Ika-chan. Also, output a line break at the end.

Example

Input

3 1 2 3 1 2 3 1 3

Output

3

inputFormat

outputFormat

output

Output the minimum value of the total damage received by AOR Ika-chan. Also, output a line break at the end.

Example

Input

3 1 2 3 1 2 3 1 3

Output

3

样例

3 1 2 3
1 2 3
1 3
3