#include <bits/stdc++.h>
using namespace std;
long long ts, tf, t;
int n;
long long a[100100], nowtime, last, nowpeople, ans, min1 = 0x3f3f3f3f3f3f3f3f;
int main() {
  int i;
  scanf("%I64d%I64d%I64d%d", &ts, &tf, &t, &n);
  for (i = 1; i <= n; i++) scanf("%I64d", &a[i]);
  last = ts;
  if (a[1] > ts) {
    printf("%I64d", ts);
    return 0;
  }
  for (i = 1; i <= n; i++) {
    nowpeople++;
    if (a[i] == a[i + 1]) {
      continue;
    }
    if (a[i] - 1 >= last) {
      if (a[i] - 1 + t <= tf) {
        printf("%I64d", last);
        return 0;
      }
    } else {
      if (last + t <= tf && last - a[i] + 1 < min1) {
        min1 = last - a[i] + 1;
        ans = a[i] - 1;
      }
    }
    last += nowpeople * t;
    nowpeople = 0;
  }
  if (last + t <= tf) {
    printf("%I64d", last);
    return 0;
  }
  printf("%I64d", ans);
  return 0;
}
