#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long long ts, tf, t;
  while (scanf("%lld %lld %lld\n", &ts, &tf, &t) != EOF) {
    long long x, r, tsi = ts, f = tf - t;
    int n;
    scanf("%d\n", &n);
    for (int i = 0; i < n; i++) {
      scanf("%lld", &x);
      if (tsi <= tf - t) {
        if (x <= tsi) {
          if (x > 0 && f > tsi - x + 1) {
            f = tsi - x + 1;
            r = x - 1;
          }
          tsi += t;
        } else {
          r = tsi;
          f = 0;
        }
      }
    }
    if (tsi <= tf - t) {
      r = tsi;
      f = 0;
    }
    printf("%lld\n", r);
  }
  return 0;
}
