#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
long long ts, tf, t, T[maxn];
int n;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> ts >> tf >> t;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> T[i];
  }
  long long waiting_time = 1e13, ans = -1;
  for (int i = 0; i < n; i++) {
    if (T[i] > 0 && ts - T[i] + 1 < waiting_time) {
      waiting_time = ts - T[i] + 1;
      ans = min(ts, T[i] - 1);
      if (waiting_time <= 0) break;
    }
    ts = max(ts, T[i]) + t;
    if (ts + t > tf) break;
  }
  if (ts <= tf - t && waiting_time > 0) ans = ts;
  cout << ans << endl;
  return 0;
}
