#include <bits/stdc++.h>
using namespace std;
const int MAX = 100005;
const long long INF = 1e12 + 7;
long long ts, tf, t, n;
long long v[MAX], ok[MAX];
int main() {
  scanf(" %lld %lld %lld %lld", &ts, &tf, &t, &n);
  if (n == 0) {
    printf("%lld\n", ts);
    return 0;
  }
  for (int i = 1; i <= n; i++) scanf(" %lld", &v[i]);
  ok[0] = ts;
  for (int i = 1; i <= n; i++) {
    if (v[i] < ok[i - 1])
      ok[i] = ok[i - 1] + t;
    else
      ok[i] = v[i] + t;
  }
  v[n + 1] = ok[n] + 1;
  long long ans = INF, pos;
  for (int i = 1; i <= n + 1; i++) {
    long long arrive = min(ok[i - 1], v[i] - 1);
    long long aux = (ok[i - 1] - arrive) + t;
    if (arrive + aux > tf)
      break;
    else {
      if (aux < ans) {
        ans = aux;
        pos = arrive;
      }
    }
  }
  printf("%lld\n", pos);
}
