#include <bits/stdc++.h>
using namespace std;
const int kMaxN = 1e5 + 10;
const long long kInf = (1LL << 60);
long long v[kMaxN];
void eval(long long& ans, long long& best, long long now,
          long long receptionist, long long end, long long time) {
  if (end - receptionist >= time) {
    if (receptionist - now < best) {
      best = receptionist - now;
      ans = now;
    }
  }
}
void solve() {
  int n;
  long long ts, tf, t;
  scanf("%lld %lld %lld", &ts, &tf, &t);
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", &v[i]);
  }
  sort(v + 1, v + n + 1);
  long long last, best = kInf, ans, receptionist = ts;
  if (v[1] != 0) {
    receptionist = max(receptionist, min(v[1] - 1, tf - t));
    eval(ans, best, min(v[1] - 1, tf - t), receptionist, tf, t);
  }
  last = v[1];
  for (int i = 1; i <= n; ++i) {
    if (v[i] != last) {
      receptionist = max(receptionist, v[i] - 1);
      eval(ans, best, v[i] - 1, receptionist, tf, t);
    }
    receptionist = max(receptionist, v[i]);
    receptionist += t;
  }
  eval(ans, best, tf - t, receptionist, tf, t);
  cout << ans << "\n";
}
int main() {
  int test = 1;
  for (; test; --test) {
    solve();
  }
}
