Finally! Vasya have come of age and that means he can finally get a passport! To do it, he needs to visit the passport office, but it's not that simple. There's only one receptionist at the passport office and people can queue up long before it actually opens. Vasya wants to visit the passport office tomorrow.

He knows that the receptionist starts working after t_{s} minutes have passed after midnight and closes after t_{f} minutes have passed after midnight (so that (t_{f} - 1) is the last minute when the receptionist is still working). The receptionist spends exactly t minutes on each person in the queue. If the receptionist would stop working within t minutes, he stops serving visitors (other than the one he already serves). 

Vasya also knows that exactly n visitors would come tomorrow. For each visitor Vasya knows the point of time when he would come to the passport office. Each visitor queues up and doesn't leave until he was served. If the receptionist is free when a visitor comes (in particular, if the previous visitor was just served and the queue is empty), the receptionist begins to serve the newcomer immediately. [Image] "Reception 1" 

For each visitor, the point of time when he would come to the passport office is positive. Vasya can come to the office at the time zero (that is, at midnight) if he needs so, but he can come to the office only at integer points of time. If Vasya arrives at the passport office at the same time with several other visitors, he yields to them and stand in the queue after the last of them.

Vasya wants to come at such point of time that he will be served by the receptionist, and he would spend the minimum possible time in the queue. Help him!


-----Input-----

The first line contains three integers: the point of time when the receptionist begins to work t_{s}, the point of time when the receptionist stops working t_{f} and the time the receptionist spends on each visitor t. The second line contains one integer n — the amount of visitors (0 ≤ n ≤ 100 000). The third line contains positive integers in non-decreasing order — the points of time when the visitors arrive to the passport office.

All times are set in minutes and do not exceed 10^12; it is guaranteed that t_{s} < t_{f}. It is also guaranteed that Vasya can arrive at the passport office at such a point of time that he would be served by the receptionist.


-----Output-----

Print single non-negative integer — the point of time when Vasya should arrive at the passport office. If Vasya arrives at the passport office at the same time with several other visitors, he yields to them and queues up the last. If there are many answers, you can print any of them.


-----Examples-----
Input
10 15 2
2
10 13

Output
12
Input
8 17 3
4
3 4 5 8

Output
2


-----Note-----

In the first example the first visitor comes exactly at the point of time when the receptionist begins to work, and he is served for two minutes. At 12 minutes after the midnight the receptionist stops serving the first visitor, and if Vasya arrives at this moment, he will be served immediately, because the next visitor would only come at 13 minutes after midnight.

In the second example, Vasya has to come before anyone else to be served.

Difficulty: interview

Starter code:

Solutions:
import math
import sys

arrival, departure, time_per_client = [int(x) for x in input().split()]
num_clients = int(input())
if num_clients > 0:
	clients_arrival = [int(x) for x in input().split()]
else:
	print(arrival)
	return

best_time = None

current_time = arrival
clients_at_queue = 0

client_to_arrive = 0
client_wait_time = [math.inf for client in clients_arrival]
client_to_leave = 0

while current_time <= departure - time_per_client:
	while client_to_arrive < num_clients and clients_arrival[client_to_arrive] <= current_time:
		clients_at_queue += 1
		client_to_arrive += 1

	if clients_at_queue == 0:
		best_time = current_time
		break
	else:
		clients_at_queue -= 1
		client_wait_time[client_to_leave] = current_time - clients_arrival[client_to_leave]
		client_to_leave += 1

		current_time += time_per_client



while (best_time is None or best_time < 0) and len(client_wait_time) > 0:
	happiest_client = client_wait_time.index(min(client_wait_time))
	best_time = clients_arrival[happiest_client] - 1

	if best_time < 0:
		client_wait_time = client_wait_time[happiest_client+1:]
		clients_arrival = clients_arrival[happiest_client+1:]


print(best_time)

inp = input().split(' ')
ts = int(inp[0])
tf = int(inp[1])
T = int(inp[2])
inp = input()
n = int(inp)

if n == 0:
    print(ts)

else:
    inp = input().split(' ')
    min_del_t = 10000000000000;
    ans = int(inp[0])-1
    t_cur = ts
    for tS in inp:
        t = int(tS)
        time_waiting = t_cur-t+1
        if t_cur < t and t_cur+T<=tf:
            ans = t_cur
            break
        else:
            if min_del_t > time_waiting and t_cur+T <= tf:
                min_del_t = time_waiting
                ans = t-1
        t_cur += T
    #print(min_del_t)
    if(t_cur+T<=tf):
        print(t_cur)
    else:
        print(ans)



import math
start,finish,time = list(map(int, input().split()))
b = int(input())

def solve():
    firstAvailableSpot = start
    minimumTimeInQueue = 10**12 + 1
    minimum = 23123
    last = 0

    for i in range(len(q)):
        if (q[i] > firstAvailableSpot) and (firstAvailableSpot + time < finish):
            return firstAvailableSpot

        timeInQueue = firstAvailableSpot - q[i]
        firstAvailableSpot += time

        if q[i] != last:
            if timeInQueue + 1 < minimumTimeInQueue:
                minimumTimeInQueue = timeInQueue + 1
                minimum = q[i] - 1
                last = q[i]
        
        if firstAvailableSpot >= finish or len(q) -1 == i:
            if firstAvailableSpot + time <= finish:
                return firstAvailableSpot
            return minimum

if b != 0:
    q = list(map(int, input().split()))
    print(solve())
else:
    print(str(start))





import sys

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def solve():
    ts, tf, t = map(int, input().split())
    n = int(input())

    if n == 0:
        print(ts)
        return None

    AT = [int(i) for i in input().split()]
    BT = [0]*n

    for i, at in enumerate(AT):
        if i == 0:
            if at > ts:
                print(ts)
                return None
            else:
                BT[i] = ts
        else:
            if at > BT[i - 1] + t and BT[i - 1] + t <= tf:
                print(BT[i - 1] + t)
                return None
            else:
                BT[i] = BT[i - 1] + t

    if BT[n - 1] + 2*t <= tf:
        print(BT[n - 1] + t)
        return None

    min_wait = float('inf')
    ans = None

    for i in range(n):
        if i > 0 and AT[i] == AT[i - 1]:
            continue
        else:
            if BT[i] - (AT[i] - 1) < min_wait and BT[i] + t <= tf:
                min_wait = BT[i] - (AT[i] - 1)
                ans = AT[i] - 1

    print(ans)

def __starting_point():
    solve()
__starting_point()

f = lambda: map(int, input().split())
a, b, t = f()
k, = f()
s = d = 1e12
for q in (f() if k else []):
    if q > a: s = a
    if q > a or a + t > b: break
    elif a - q < d: s, d = q - 1, a - q
    a += t
print(s if a + t > b else a)

s, e, t_per_v = list(map(int, input().split()))
e -= t_per_v
n = int(input())
if n > 0:
    visitors = list(map(int, input().split()))
else:
    visitors=[]

min_wait_time = float("inf")
min_arrive_time = -1
visitor_index = 0
t = s
while t <= e:
    # print(t, visitor_index)
    if visitor_index >= len(visitors) or visitors[visitor_index] > t:
        print(t)
        return
    wait_time = t - visitors[visitor_index]
    if wait_time < min_wait_time:
        min_wait_time = wait_time
        min_arrive_time = visitors[visitor_index]
    t += t_per_v
    visitor_index += 1
print(min_arrive_time - 1)


s, e, t_per_v = list(map(int, input().split()))
e -= t_per_v
n = int(input())
if n > 0:
    visitors = list(map(int, input().split()))
else:
    visitors=[]

min_wait_time = float("inf")
min_arrive_time = -1
visitor_index = 0
t = s
while t <= e:
    if visitor_index >= len(visitors) or visitors[visitor_index] > t:
        print(t)
        return
    wait_time = t - visitors[visitor_index]
    if wait_time < min_wait_time:
        min_wait_time = wait_time
        min_arrive_time = visitors[visitor_index]
    t += t_per_v
    visitor_index += 1
print(min_arrive_time - 1)

# 1535294397513


# 

def update(t, l, ans):
    if l < ans[1]:
        ans[0] = t
        ans[1] = l
    
def solve():
    S, E, L = list(map(int, input().split()))
    
    n       = int(input())
    if n == 0:
        return S
    
    a       = list(map(int, input().split()))[::-1]

    if S < a[-1]:
        return S
    
    ans = [0, S]
    cur_t = S
    
    while cur_t+L <= E and len(a) > 0:
        if cur_t < a[-1]:
            return cur_t
        
        t  = a.pop()
        update(t-1, cur_t-t+1, ans)
        cur_t+=L    
    
    if cur_t+L <= E:
        return cur_t
    
    return ans[0]

print(solve())        
#10 15 2
#2
#10 13    

#8 17 3
#4
#3 4 5 8