#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const long long INF = 1e18;
long long a[N], t;
long long get(long long pre, long long x) {
  if (x < pre) return pre + t - 1;
  return x + t - 1;
}
int main() {
  long long start, ent;
  scanf("%lld%lld%lld", &start, &ent, &t);
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
  }
  a[n + 1] = INF;
  long long pre = start, answer = INF, pos = 0;
  if (a[1] > start) {
    answer = t;
    pos = start;
  }
  if (answer > get(pre, a[1] - 1) - (a[1] - 1) + 1 && a[1] - 1 >= 0) {
    if (get(pre, a[1] - 1) <= ent - 1) {
      answer = get(pre, a[1] - 1) - (a[1] - 1) + 1;
      pos = a[1] - 1;
    }
  }
  for (int i = 1; i <= n; i++) {
    pre = get(pre, a[i]) + 1;
    if (get(pre, pre) > ent - 1) break;
    if (a[i] != a[i + 1]) {
      if (answer > get(pre, a[i + 1] - 1) - (a[i + 1] - 1) + 1) {
        if (get(pre, a[i + 1] - 1) > ent - 1) continue;
        answer = get(pre, a[i + 1] - 1) - (a[i + 1] - 1) + 1;
        pos = a[i + 1] - 1;
      }
      if (pre < a[i + 1]) {
        if (answer > get(pre, pre) - pre + 1) {
          if (get(pre, pre) > ent - 1) continue;
          answer = get(pre, pre) - pre + 1;
          pos = pre;
        }
      }
    }
  }
  if (get(pre, pre) <= ent - 1) {
    if (answer > get(pre, pre) - pre + 1) {
      answer = get(pre, pre) - pre + 1;
      pos = pre;
    }
  }
  printf("%lld\n", pos);
}
