If the girl doesn't go to Denis, then Denis will go to the girl. Using this rule, the young man left home, bought flowers and went to Nastya. 

On the way from Denis's house to the girl's house is a road of $n$ lines. This road can't be always crossed in one green light. Foreseeing this, the good mayor decided to place safety islands in some parts of the road. Each safety island is located after a line, as well as at the beginning and at the end of the road. Pedestrians can relax on them, gain strength and wait for a green light.

Denis came to the edge of the road exactly at the moment when the green light turned on. The boy knows that the traffic light first lights up $g$ seconds green, and then $r$ seconds red, then again $g$ seconds green and so on.

Formally, the road can be represented as a segment $[0, n]$. Initially, Denis is at point $0$. His task is to get to point $n$ in the shortest possible time.

He knows many different integers $d_1, d_2, \ldots, d_m$, where $0 \leq d_i \leq n$  — are the coordinates of points, in which the safety islands are located. Only at one of these points, the boy can be at a time when the red light is on.

Unfortunately, Denis isn't always able to control himself because of the excitement, so some restrictions are imposed:  He must always move while the green light is on because it's difficult to stand when so beautiful girl is waiting for you. Denis can change his position by $\pm 1$ in $1$ second. While doing so, he must always stay inside the segment $[0, n]$.  He can change his direction only on the safety islands (because it is safe). This means that if in the previous second the boy changed his position by $+1$ and he walked on a safety island, then he can change his position by $\pm 1$. Otherwise, he can change his position only by $+1$. Similarly, if in the previous second he changed his position by $-1$, on a safety island he can change position by $\pm 1$, and at any other point by $-1$.  At the moment when the red light is on, the boy must be on one of the safety islands. He can continue moving in any direction when the green light is on. 

Denis has crossed the road as soon as his coordinate becomes equal to $n$.

This task was not so simple, because it's possible that it is impossible to cross the road. Since Denis has all thoughts about his love, he couldn't solve this problem and asked us to help him. Find the minimal possible time for which he can cross the road according to these rules, or find that it is impossible to do.


-----Input-----

The first line contains two integers $n$ and $m$ $(1 \leq n \leq 10^6, 2 \leq m \leq min(n + 1, 10^4))$  — road width and the number of safety islands.

The second line contains $m$ distinct integers $d_1, d_2, \ldots, d_m$ $(0 \leq d_i \leq n)$  — the points where the safety islands are located. It is guaranteed that there are $0$ and $n$ among them.

The third line contains two integers $g, r$ $(1 \leq g, r \leq 1000)$  — the time that the green light stays on and the time that the red light stays on.


-----Output-----

Output a single integer  — the minimum time for which Denis can cross the road with obeying all the rules.

If it is impossible to cross the road output $-1$.


-----Examples-----
Input
15 5
0 3 7 14 15
11 11

Output
45
Input
13 4
0 3 7 13
9 9

Output
-1


-----Note-----

In the first test, the optimal route is:       for the first green light, go to $7$ and return to $3$. In this case, we will change the direction of movement at the point $7$, which is allowed, since there is a safety island at this point. In the end, we will be at the point of $3$, where there is also a safety island. The next $11$ seconds we have to wait for the red light.      for the second green light reaches $14$. Wait for the red light again.      for $1$ second go to $15$. As a result, Denis is at the end of the road. 

In total, $45$ seconds are obtained.

In the second test, it is impossible to cross the road according to all the rules.

Difficulty: interview

Starter code:

Solutions:
import collections

n,m=map(int,input().split())
m+=2
arr=list(map(int,input().split()))
arr.append(0)
arr.append(n)
arr=sorted(arr)
g,r=map(int,input().split())
q=collections.deque()
q.append((0,0))
dist=[[0]*(g+1) for _ in range(m+2)]
checked=[[0]*(g+1) for _ in range(m+2)]
checked[0][0]=1
ans=-1
while len(q)!=0:
  v,t=q.popleft()
  if t==0:
    if n-arr[v]<=g:
      tmp=dist[v][t]*(g+r)+n-arr[v]
      if ans==-1 or ans>tmp:
        ans=tmp
  if t==g:
    if checked[v][0]==0:
      checked[v][0]=1
      dist[v][0]=dist[v][t]+1
      q.append((v,0))
    continue
  if v!=0:
    cost=t+arr[v]-arr[v-1]
    if cost<=g and checked[v-1][cost]==0:
      checked[v-1][cost]=1
      dist[v-1][cost]=dist[v][t]
      q.appendleft((v-1,cost))
  if v!=m-1:
    cost=t+arr[v+1]-arr[v]
    if cost<=g and checked[v+1][cost]==0:
      checked[v+1][cost]=1
      dist[v+1][cost]=dist[v][t]
      q.appendleft((v+1,cost))
print(ans)

import collections

n,m=map(int,input().split())
arr=list(map(int,input().split()))
arr=sorted(arr)
g,r=map(int,input().split())
q=collections.deque()
q.append((0,0,0))
checked=[[-1]*(g) for _ in range(m)]
checked[0][0]=0
while len(q)!=0:
  v,t,cnt=q.popleft()
  if v!=m-1:
    cost1=arr[v+1]-arr[v]
    if t+cost1<=g:
      if checked[v+1][(t+cost1)%g]==-1:
        if t+cost1<g:
          q.appendleft((v+1,t+cost1,cnt))
          checked[v+1][t+cost1]=cnt
        else:
          q.append((v+1,0,cnt+1))
          checked[v+1][0]=cnt+1
  if v!=0:
    cost2=arr[v]-arr[v-1]
    if t+cost2<=g:
      if checked[v-1][(t+cost2)%g]==-1:
        if t+cost2<g:
          q.appendleft((v-1,t+cost2,cnt))
          checked[v-1][t+cost2]=cnt
        else:
          q.append((v-1,0,cnt+1))
          checked[v-1][0]=cnt+1
ans=10**18
for i in range(m):
  for j in range(g):
    if checked[i][j]==-1:
      continue
    else:
      if j+n-arr[i]<=g:
        ans=min(ans,checked[i][j]*(g+r)+j+n-arr[i])
if ans==10**18:
  print(-1)
else:
  print(ans)

import sys
input = sys.stdin.readline
from collections import deque
from typing import List

############ ---- Input Functions ---- ############
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(list(map(int,input().split())))


def compute(n, m, g, r, A: List[int]):
    A.sort()

    WHITE = -1
    GREY = -2

    states = [[WHITE] * (g+1) for _ in range(m)]
    states[0][g] = 0
    states[0][0] = 0

    q = deque([(0, g)])

    def process_neib(ineib, gneib):
        if states[ineib][gneib] != WHITE:
            #print(f"Skipped as grey")
            return

        if ineib == m-1:
            #no need to wait there
            states[ineib][gneib] = states[index][g_left]
            #print(f"Final state dist is {states[ineib][gneib]}")

        elif gneib == 0:
            states[ineib][gneib] = states[index][g_left] + 1
            states[ineib][g] = states[ineib][gneib]
            gneib = g
            q.append((ineib, gneib))
            #print(f"appended right with distance {states[ineib][0]}")
        else:
            states[ineib][gneib] = states[index][g_left]
            q.appendleft((ineib, gneib))

    while q:
        # sit for this is known
        #print(f"Queue is {[(A[i], t) for i,t in q]}")
        index, g_left = q.popleft()
        #print(f"Popped {A[index], g_left}. Dist is {states[index][g_left]}")


        #neib = get_neib(index, g_left, A)
        #print(f"Neighbors are {[(A[i], t) for i, t in neib]}")

        if index > 0:
            # there exists a next one
            delta = A[index] - A[index-1]
            if g_left >= delta:
                process_neib(index-1, g_left-delta)


        if index < m-1:
            delta = A[index+1] - A[index]
            if g_left >= delta:
                process_neib(index+1, g_left-delta)


                #print(f"appended left with distance {states[ineib][gneib]}")


    res = float('inf')
    for g_left in range(g):
        if states[m-1][g_left] >= 0:

            res = min(res, states[m-1][g_left] * (r+g) + g-g_left)

    if res != float('inf'):
        print(res)
    else:
        print('-1')


def from_file(f):
    return f.readline

# with open('52.txt') as f:
#     input = from_file(f)
n, m = invr()
A = inlt()
g,r  = invr()
compute(n, m, g, r, A)








import sys
sys.setrecursionlimit(10000)

from collections import deque
from heapq import heappush, heappop

class Memoize:
    def __init__(self, f):
        self.f = f
        self.memo = {}
    def __call__(self, *args):
        if not args in self.memo:
            self.memo[args] = self.f(*args)
        return self.memo[args]

class Recurse(Exception):
    def __init__(self, *args, **kwargs):
        self.args = args
        self.kwargs = kwargs

def recurse(*args, **kwargs):
    raise Recurse(*args, **kwargs)
        
def tail_recursive(f):
    def decorated(*args, **kwargs):
        while True:
            try:
                return f(*args, **kwargs)
            except Recurse as r:
                args = r.args
                kwargs = r.kwargs
                continue
    return decorated

n, m = list(map(int, input().split()))
d = sorted(map(int, input().split()))
g, r = list(map(int, input().split()))

q = deque([(0, 0, g)])
cost = [[-1] * (g+1) for _ in range(m)]

while len(q):
    c, x, t = q.popleft()
    if cost[x][t] != -1:
        continue
    cost[x][t] = c
    back = False
    if t == 0:
        back = True
        c += r
        t = g
    for di in [-1, 1]:
        ni = x+di
        if ni >= 0 and ni < m:
            step = abs(d[x]-d[ni])
            if step <= t:
                if back:
                    q.append((c+step, ni, t-step))
                else:
                    q.appendleft((c+step, ni, t-step))

res = list([x for x in cost[m-1] if x != -1])
print(min(res) if len(res) else -1)