#include <bits/stdc++.h>
using namespace std;
long long ts, tf, t, tmp, nt;
int n, cnt, ans;
long long ti[100010];
struct node {
  long long id, len;
  friend bool operator<(const node &a, const node &b) { return a.len < b.len; }
} nod[100010];
struct hehe {
  long long id, ci;
} h[100010];
int main() {
  cin >> ts >> tf >> t >> n;
  for (int i = 1; i <= n; i++) scanf("%I64d", &ti[i]);
  for (int i = 1; i <= n; i++) {
    if (ti[i] >= tf) break;
    if (ti[i] != ti[i - 1]) {
      h[cnt].id = ti[i];
      h[cnt++].ci++;
    } else {
      h[cnt - 1].ci++;
    }
  }
  if (cnt == 0) {
    cout << ts;
    exit(0);
  }
  h[cnt].id = tf - t + 1;
  long long tmp, ps;
  long long wait_time = ts - (ti[1] - 1);
  ps = ti[1] - 1;
  if (wait_time < 0) wait_time = 0;
  nod[ans].id = ti[1] - 1;
  nod[ans++].len = wait_time;
  wait_time += t * h[0].ci;
  for (int i = 1; i <= cnt; i++) {
    tmp = wait_time + ps - (h[i].id - 1);
    ps = h[i].id - 1;
    if (tmp < 0) tmp = 0;
    if (h[i].id - 1 + tmp + t > tf) break;
    nod[ans].id = h[i].id - 1;
    nod[ans++].len = tmp;
    wait_time = tmp;
    wait_time += t * h[i].ci;
  }
  sort(nod, nod + ans);
  cout << nod[0].id;
  return 0;
}
