Under construction

Still being built. Things may change

Sleeping on the Train

Time limit2sMemory limit2048 MB

Summary
Given a train that shuttles between stops 1 and n, find the fewest turnarounds it makes while Antonio rides from stop a to stop b, using t sleep-wake sightings to pin its position.
Level

Medium6 of 10

Topics
Math, Greedy, Simulation
Solved
No attempts yet

Problem

Antonio is sightseeing in Line Town. As part of the trip, he rides the famous Line Train. The train serves nn stops, numbered 1 to nn. It starts at stop 1 and moves through the stops in increasing order until it reaches stop nn. There it turns around and moves through the stops in decreasing order until it reaches stop 1, where it turns around again and repeats the journey.

When the train arrives at stop 1 or stop nn, all passengers who want to get off leave the train. Then the train turns around, and new passengers board before it heads to the next stop.

Antonio travels from stop aa to stop bb. He is very sleepy and does not check the direction of the train when he boards, so he may board a train that is heading the wrong way. Right after he boards, he falls asleep. He wakes up tt times during the trip. Each time, he sees that the train is between stop sis_i and stop si+1s_i+1. He cannot tell which direction the train is moving. Since he is not at his destination yet, he falls back asleep right away.

After the tt-th time he wakes up, Antonio stays awake for the rest of the trip. He remains on the train until it next stops at stop bb, and then he gets off.

Find the minimum number of times the train turned around while Antonio was on it.

Input

The first line contains four integers nn (2≤n≤1092 \le n \le 10^9), tt (1≤t≤1051 \le t \le 10^5), aa, and bb (1≤a,b≤n1 \le a, b \le n, a≠ba \neq b).

The second line contains tt integers. The ii-th integer sis_i (1≤si<n1 \le s_i < n) means that when Antonio woke up for the ii-th time, the train was between stop sis_i and stop si+1s_i+1.

Output

Print the minimum number of times the train turned around while Antonio was on it.

Examples2

  1. Example 1

    Input
    10 1 5 3
    4
    
    Expected output
    0
    
  2. Example 2

    Input
    10 2 5 3
    5 4
    
    Expected output
    1