#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10, inf = 1e9 + 10, MOD = 1e9 + 7, Sq = 225, pr = 522017,
          PR = 71;
const long long INF = 1e18 + 10;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long ts, tf, t, mx = INF, ans, x, res = -1;
  int n;
  cin >> ts >> tf >> t >> n;
  if (n == 0) {
    cout << ts;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (i == 0 && x > ts) {
      cout << ts;
      return 0;
    }
    long long sum = 0;
    if (x - 1 < ts && res == -1) sum += ts - (x - 1);
    if (res >= x - 1) sum += (res - (x - 1) + 1);
    if (res == -1 || res + t <= (tf - 1)) {
      if (sum < mx) {
        mx = sum;
        ans = x - 1;
      }
    }
    if (i == 0)
      res = max(x, ts) + t - 1;
    else
      res = max(res + t, x + t - 1);
  }
  if ((tf - 1) - (res) >= t) {
    ans = res + 1;
    mx = 0;
  }
  cout << ans;
  return 0;
}
