#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long long INF64 = 1e18;
const int N = 101;
const int M = 16;
const long long MOD = 1000000007;
const long double Pi = 3.1415926535897932384626433832795;
const long double EPS = 1e-9;
int main() {
  long long ts, tf, t;
  cin >> ts >> tf >> t;
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < int(n); i++) scanf("%I64d", &a[i]);
  vector<pair<long long, long long> > b(n);
  long long ans = -1;
  long long res = INF64;
  long long cur = ts;
  for (int i = 0; i < int(n); i++) {
    if (a[i] > cur) {
      if (cur + t <= tf) {
        cout << cur << endl;
        return 0;
      }
      cur = a[i];
    }
    b[i] = make_pair(cur, cur + t);
    cur += t;
  }
  if (cur + t <= tf) {
    cout << cur << endl;
    return 0;
  }
  for (int i = 0; i < int(n); i++) {
    if (b[i].first - a[i] + 1 < res && b[i].second <= tf) {
      ans = a[i] - 1;
      res = b[i].first - a[i] + 1;
    }
  }
  cout << ans << endl;
}
