#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  long long n, a, ts, tf, t, r = -1;
  long long kv = 1e14;
  cin >> ts >> tf >> t >> n;
  long long tb = ts;
  for (int i = 1; i <= n; i++) {
    cin >> a;
    if (tb + t > tf) continue;
    if (a - tb > 0) {
      r = tb, kv = 0;
    } else {
      long long ttb = max(0ll, a - 1);
      if (kv > tb - ttb && tb + t <= tf) kv = tb - ttb, r = ttb;
      tb += t;
    }
  }
  if (tb + t <= tf) r = tb;
  cout << r;
  return 0;
}
