#include <bits/stdc++.h>
using namespace std;
long long a[100010];
vector<pair<long long, long long> > people;
long long Free[100010];
int main() {
  long long ts, tf, t;
  cin >> ts >> tf >> t;
  int n;
  scanf("%d", &n);
  if (n == 0) {
    cout << ts << endl;
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    scanf("%I64d", &a[i]);
  }
  people.push_back(make_pair(0, 0));
  long long cnt = 1;
  for (int i = 1; i < n; i++) {
    if (a[i] != a[i + 1]) {
      people.push_back(make_pair(a[i], cnt));
      cnt = 1;
    } else
      cnt++;
  }
  people.push_back(make_pair(a[n], cnt));
  long long ans, wait;
  ans = a[1] - 1;
  wait = ts - (a[1] - 1);
  if (wait < 0) {
    wait = 0;
    ans = ts;
  }
  long long time = max(people[1].first, ts);
  for (int i = 1; i + 1 < people.size(); i++) {
    if (time + t > tf) break;
    time = time + people[i].second * t;
    if (time + t > tf) break;
    long long come_time = people[i + 1].first - 1;
    long long new_wait = time - come_time;
    if (new_wait < 0) {
      new_wait = 0;
      come_time = time;
    }
    if (new_wait < wait) {
      wait = new_wait;
      ans = come_time;
    }
    time = max(time, people[i + 1].first);
  }
  time = time + people.back().second * t;
  if (time + t <= tf) {
    ans = time;
    wait = 0;
  }
  cout << ans << endl;
  return 0;
}
