#include <bits/stdc++.h>
using namespace std;
long long n, A[100005], ts, tf, t, min_wait = 1000000000000000005, q = 0,
                                   wasted = 0, ans = -1;
int main() {
  cin >> ts >> tf >> t;
  cin >> n;
  A[0] = -t + 1;
  for (int i = 1; i <= n; i++) cin >> A[i];
  A[n + 1] = tf;
  long long temp = 0;
  for (int i = 1; i <= n + 1; i++) {
    long long possible_position = A[i] - 1;
    if (possible_position < 0) continue;
    temp = 0;
    long long ab = i - 1;
    if (possible_position < ts) {
      temp = max(ab * t + ts - possible_position, A[i - 1] + t - 1);
      if (temp < min_wait && temp + t < tf) {
        min_wait = temp;
        ans = possible_position;
      }
    }
    temp = max(ts + ab * t - 1, A[i - 1] + t - 1);
    if ((temp) >= possible_position) {
      if (temp + t < tf && (temp - possible_position + 1) < min_wait) {
        ans = possible_position;
        min_wait = (temp - possible_position + 1);
      }
      continue;
    }
    if (temp < possible_position) {
      if ((temp + t) < tf) {
        min_wait = 0;
        ans = temp + 1;
        break;
      }
      continue;
    }
  }
  cout << ans << endl;
}
