#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
long long arr[100005];
int main() {
  std::ios::sync_with_stdio(false);
  long long ts, tf, k;
  cin >> ts >> tf >> k;
  int n;
  cin >> n;
  multiset<long long> st;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    st.insert(-arr[i]);
  }
  long long wait1 = 1e18;
  long long time1 = ts;
  long long curr_time = max(ts, arr[0]) + k;
  if (arr[0] > 0 && arr[0] < tf) {
    time1 = arr[0] - 1;
    wait1 = min(wait1, max(0LL, ts - time1));
  }
  for (int i = 1; i < n && curr_time < tf; i++) {
    long long finish1 = curr_time;
    long long arrive = min(finish1, arr[i] - 1);
    long long tmp = finish1 - arrive;
    if (tmp < wait1) {
      wait1 = tmp;
      time1 = arrive;
    }
    curr_time = max(curr_time + k, arr[i] + k);
  }
  if (curr_time <= tf - k) {
    time1 = curr_time;
  }
  cout << time1 << "\n";
}
