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 ts minutes have passed after midnight and closes after tf minutes have passed after midnight (so that (tf - 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 ts, the point of time when the receptionist stops working tf 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 1012; it is guaranteed that ts < tf. 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. 
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.util.*;

/**
 * Created by Firеfly on 1/1/2017.
 */
public class Task {
    public static void main(String[] args) throws IOException {
        Emaxx emaxx = new Emaxx();
    }
}


class Emaxx {
    static char[] checker;
    FScanner fs;
    PrintWriter pw;
    long MOD = 1000000007;
    HashMap<Integer, Integer> map[];
    int[] parent;
    int[] mmas;
    int n, m;
    long[][] desk;
    boolean used[];
    ArrayList<Integer> graph[];
    HashMap<Integer, Integer>[] answer;
    int max;
    int[] hi;
    Emaxx() throws IOException {
        fs = new FScanner(new InputStreamReader(System.in));
        // pw = new PrintWriter(new FileWriter("arithnumbers.out"));
        //  fs = new FScanner(new FileReader("C:\\Users\\Firеfly\\Desktop\\New Text Document.txt"));
        //     fs = new FScanner(new FileReader("input.txt"));;
        //       pw = new PrintWriter("output.txt");
        pw = new PrintWriter(System.out);
        long ts = fs.nextLong(), tf = fs.nextLong(), t = fs.nextLong();
        int n = fs.nextInt();
        if (n == 0)
        {
            System.out.println(ts);
            System.exit(0);
        }
        long[] mas = new long[n];
        for (int i = 0; i<n; i++)
            mas[i] = fs.nextLong();
        long time = 0;
        int pos = 0;
        int j = 0;
        long timeprev = ts;
        while (j<n && mas[j]<=ts)
        {
            pos++;
            j++;
        }
        time = pos*t+ts;
        for (; j<n; j++) {
            if (time+t>tf)
                break;
            if (mas[j]<=time)
                time+=t;
            else if (time+t<=tf){
                System.out.println(time);
                System.exit(0);
            }
            else break;
        }
        if (time+t<=tf)
            System.out.println(time);
        else {
            long min = 0;
            long mins = ts+t;
            int pl = 0;
            for (; pl<n; pl++) {
                if ((ts+(pl)*t+t<=tf) && (ts+(pl)*t+t-(mas[pl]-1)<mins))
                {
                    mins = ts+(pl)*t+t-(mas[pl]-1);
                    min = mas[pl]-1;
                }
            }
            System.out.println(min);
        }
        pw.close();
    }

    int make(int[][] orig, int[] combs) {
        for (int i = 3; i<10; i++) {
            for (int j = 0; j<3; j++) {
                int curp = 0;
                int f = 0;
                int s = 1;
                int th = 2;
                if (combs[0] == 1)
                    f+=j;
                if (combs[2] == 1)
                    s+=j;
                if (combs[4] == 1)
                    th+=j;
                int f1 = 0;
                int s1 = 0;
                int th1 = 0;
                if (combs[1] == 1)
                    f1 = i-3;
                if (combs[3] == 1)
                    s1 = i-3;
                if (combs[5] == 1)
                    th1 = i-3;
                orig[i][j] = orig[f1][f] + orig[s1][s] + orig[th1][th];
            }
        }
        return orig[9][2];
    }
    int inv(Pair mas[]) {
        int ans = 0;
        for (int i = 1; i<n; i++) {
            System.out.println(mas[i].x + " " + mas[i].y);
            for (int j = i-1; j>=0; j--) {
                if (mas[j].y>mas[i].y)
                    ans++;
            }
        }
        return ans;
    }


    double len(double x1, double x2, double y1, double y2) {
        return Math.sqrt((x2-x1)*(x2-x1)+(y1-y2)*(y1-y2));
    }

    int find(int cub, int prev) {
        if (cub == 0)
            return 1;
        int ans = 0;
        for (int i = prev+1; i<=cub; i++) {
            ans+=find(cub-i, i);
        }
        return ans;
    }
    int findNum(char[] mas) {
        int size = 1;
        int i  =0 , j = 0;
        for (i = 1,j = mas.length-1; i<=j; i++, j--)
            if ((mas[i]>='0' && mas[i]<='9') || (mas[j]>='0' && mas[j] <='9'))
                break;
            else size++;
        if (i>j)
            return -1;
        else
            return size;
    }

    int findsymb(char[] mas) {
        int size = 1;
        int i = 0, j = 0;
        for (i = 1,j = mas.length-1; i<=j; i++, j--)
            if ((mas[i]>='a' && mas[i]<='z') || (mas[j]>='a' && mas[j] <='z'))
                break;
            else size++;
        if (i>j)return -1;
        else
            return size;
    }

    int findlitts(char[] mas) {
        int size = 1;
        int i= 0, j = 0;
        for (i = 1,j = mas.length-1; i<=j; i++, j--)
            if (mas[i]=='&' || mas[i]=='*' || mas[i] == '#' || mas[j]=='*' || mas[j] =='#' || mas[j] == '&')
                break;
            else size++;
        if (i>j)
            return -1;
        else
            return size;
    }

    boolean ans(int[] second, int first[], int start) {
        int fir = 0;
        int sec = start;
        while (sec<n && first[0] != second[sec])
            sec++;
        int p = sec;
        if (sec == n) {
            return false;}
        else {
            while (sec<n && first[fir] == second[sec])
            {
                sec++;
                fir++;
            }
            if (sec!=n) {
                return false;
            }
            else {
                sec = 0;
                while (sec < p && second[sec] == first[fir]) {
                    sec++;
                    fir++;
                }
                if (sec != p)
                    return false;
                else
                    return true;
            }
        }
    }

    void dfs(int v, int p, int from) {
        if (from !=-1)
            answer[v].put(from, p);
        used[v] = true;
        int label = 1;
        for (int i = 0; i<graph[v].size(); i++) {
            if (!used[graph[v].get(i)]) {
                if (label == p)
                    label++;
                used[graph[v].get(i)] = true;
                answer[v].put(graph[v].get(i),label);
                dfs(graph[v].get(i), label, v);
                label++;
            }
        }
    }



    int gcd (int a, int b) {
        if (b == 0)
            return a;
        else
            return gcd(b, a % b);
    }



    /*

        int l1 = le[le.length-1]-46;
        int l2 = le[le.length-2]-46;
        if (l1>=l2)
            l1-=l2;
        else l1 = l1+10-l2;
        System.out.println(l1);
        long ll = dp[le.length][l1];
        int r1 = re[re.length-1]-46;
        int r2 = re[re.length-2]-46;
        if (r1>=r2)
            r1 -=r2;
        else r1 = r1+10-r2;
        long rr = dp[re.length][r1];
     */
    void PP(int[] mas) {
        System.out.println("WAT");
        ArrayList<Character> list = new ArrayList<>();
        for (int i = 0; i<mas.length; i++) {
            System.out.println(mas[i]);
            while (mas[i] > 0) {
                list.add((char) (i + 48));
                mas[i]--;
            }
        }
        Collections.sort(list);
        for (int i = list.size()-1; i>=0; i--)
            pw.print(list.get(i));
    }

    boolean good(int i, int j) {
        if ((i>=0) && (i<n) && (j>=0) && (j<m))
            return true;
        else return false;
    }

    long solve(int i, int j) {
        if (good(i, j))
        {
            if (desk[i][j]==0)
                desk[i][j] += solve(i-1, j-2)+solve(i-2, j-1)+solve(i+1, j-2)+solve(i-2, j+1);
        } else return 0;
        return desk[i][j];
    }
    boolean check(char c) {
        for (int i = 0;i<checker.length; i++)
            if (c == checker[i])
                return true;
        return false;
    }
    void make_set (int v) {
        parent[v] = v;
    }

    int find_set (int v) {
        if (v == parent[v])
            return v;
        return find_set (parent[v]);
    }

    void union_sets (int a, int b) {
        a = find_set (a);
        b = find_set (b);
        if (a != b)
            parent[b] = a;
    }

    static class IntegerUtils {
        public static long[] generateFactorials(int limit, long MOD) {
            long[] result = new long[limit];
            result[0] = 1;
            if (limit == 0) return result;
            for (int i = 1; i < limit; ++i) {
                result[i] = (result[i - 1] * i) % MOD;
            }
            return result;
        }
    }

    int[] Z_function(char[] arr) { //начинается как в начале и идёт как в начале
        int n = arr.length;
        int[] z = new int[n];
        z[0] = 0;
        for (int i = 1, l = 0, r = 0; i<n; i++) {
            if (i<=r)
                z[i] = Math.min(r-i+1, z[i-l]);
            while (i+z[i]<n && arr[i+z[i]] == arr[z[i]])
                z[i]++;
            if (i+z[i]-1>r)
            {
                l = i;
                r = i+z[i]-1;
            }
        }
        return z;
    }

    int[] prefix_function(char[] arr) { // оканчивается на этот символ
        int n = arr.length;
        int[] z = new int[n];
        for (int i = 1; i<n; i++) {
            int j = z[i-1];
            while (j>0 && arr[i] != arr[j]) {
                j=z[j-1];
            }
            if (arr[i] == arr[j]) j++;
            z[i] = j;
        }
        return z;
    }

    long substrings_string(char[] arr) {
        int p = 31;
        int n = arr.length;
        long[] pows = new long[n];
        pows[0] = 1;
        for (int i = 1; i<n; i++)
            pows[i] = pows[i-1]*p;
        long[] prefixes = new long[n];
        for (int i = 0; i<n; i++) {
            prefixes[i] = (arr[i]-'a'+1)*pows[i];
            if (i!=0) prefixes[i]+=prefixes[i-1];
        }

        long res = 0;
        for (int l = 1; l<=n; l++) {
            HashSet<Long> hh = new HashSet<>();
            for (int i = 0; i<n-l+1; i++) {
                long cur_hash = prefixes[i+l-1];
                if (i!=0) cur_hash-=prefixes[i-1];
                cur_hash *= pows[n-i-1];
                hh.add(cur_hash);
            }
            res+=hh.size();
        }
        return res;
    }

    void rabin_Karp(char[] t, char[] s) {
        int p = 31;
        long[] p_pow = new long[Math.max(t.length, s.length)];
        p_pow[0] = 1;
        for (int i = 1; i<p_pow.length; i++)
            p_pow[i] = p_pow[i-1]*p;
        long main_hash = 0;
        for (int i = 0; i<s.length; i++)
            main_hash+=(s[i]-'a'+1)*p_pow[i];
        long hashes[] = new long[t.length];
        for (int i = 0; i<t.length; i++) {
            hashes[i] = (t[i]-'a'+1)*p_pow[i];
            if (i!=0) hashes[i]+=hashes[i-1];
        }
        for (int i = 0; i+s.length-1<t.length; i++) {
            long cur_h = hashes[i+s.length-1];
            if (i!=0) cur_h-=hashes[i-1];
            if (cur_h*p_pow[i] == main_hash)
                System.out.println(i);
        }
    }

    int[] podpalindroms(ArrayList<Character> s) {
        int n = s.size();
        int[] d1 = new int[n]; //odd
        int l = 0;
        int r = -1;
        for(int i = 0; i < n; i++) {
            int k;
            if (i > r) k = 1;
            else k = Math.min(d1[l + r - i], r - i);

            while (0 <= i - k && i + k < n && s.get(i - k) == s.get(i + k)) k++;
            d1[i] = k;
            if (i + k - 1 > r) {
                r = i + k - 1;
                l = i - k + 1;
            }
        }
        int[] res = new int[n];
        for (int i = 0; i<n; i++) {
            System.out.print(d1[i] + " ");
            res[i] = d1[i];
        }
        System.out.println();
        return res;
    }



}

class FScanner {
    BufferedReader br;
    StringTokenizer st;
    FScanner(InputStreamReader isr) {
        br = new BufferedReader(isr);
    }

    FScanner(FileReader fr) {
        br = new BufferedReader(fr);
    }

    String nextToken() throws IOException{
        while (st == null || !st.hasMoreTokens()) {
            String s = br.readLine();
            if (s == null)
                return null;
            st = new StringTokenizer(s);
        }
        return st.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    String nextLine() throws IOException {
        return br.readLine();
    }

    char nextChar() throws IOException {
        return (char) br.read();
    }

}

class Gangsta  {
    int t, s, p;
    void setT(int t1) {
        t = t1;
    }
    void setS(int s1) {
        s = s1;
    }
    void setP(int p1) {
        p = p1;
    }


}

class Pair implements Comparable<Pair> {
    int y, x;
    Pair(int x1, int y1) {
        x = x1;
        y = y1;
    }
    @Override
    public int compareTo(Pair o) {
        return Integer.compare(x, o.x);
    }
}
