#include <bits/stdc++.h>
using namespace std;
long long ara[100005], n, ts, tf, t;
int main() {
  long long i, j, k, p, q, x, y;
  scanf("%I64d %I64d %I64d", &ts, &tf, &t);
  scanf("%I64d", &n);
  for (i = 0; i < n; i++) scanf("%I64d", &ara[i]);
  ara[i] = 100000000000000LL;
  p = 10000000000000000LL, q = 0;
  for (i = 0; i <= n; i++) {
    if (i && ara[i] == ara[i - 1]) {
      if (i == 1)
        q = max(ara[0], ts) + t;
      else
        q = max(q + t, ara[i - 1] + t);
      continue;
    }
    if (!i) {
      k = ara[i] - 1;
      if (k < ts)
        p = ts - k;
      else
        p = 0, k = ts;
      continue;
    }
    if (i == 1)
      q = max(ts, ara[0]) + t;
    else
      q = max(q + t, ara[i - 1] + t);
    if (q >= tf) break;
    x = ara[i] - 1;
    if (x >= q && q + t <= tf + 1)
      p = 0, k = q;
    else if (q + t <= tf + 1) {
      if (p > q - x) p = q - x, k = x;
    }
  }
  printf("%I64d\n", k);
  return 0;
}
