#include <bits/stdc++.h>
using namespace std;
long long val[100010];
int main() {
  long long ts, tf, t;
  int n;
  scanf("%I64d%I64d%I64d%d", &ts, &tf, &t, &n);
  long long work = ts;
  long long min = 1e15;
  long long fin;
  for (int i = 1; i <= n; i++) scanf("%I64d", &val[i]);
  for (int i = 1; i <= n; i++) {
    if (val[i] > work && work + t <= tf) {
      printf("%I64d\n", work);
      return 0;
    }
    if (((i == 1 && val[i] != 0) || (val[i] != val[i - 1])) && work + t <= tf &&
        work + t + 1 - val[i] < min) {
      min = work + t + 1 - val[i];
      fin = val[i] - 1;
    }
    work += t;
  }
  if (work + t <= tf) fin = work;
  printf("%I64d\n", fin);
  return 0;
}
