#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
long long s, t, per;
int n;
long long a[N], b[N];
int main() {
  ios::sync_with_stdio(0);
  cin >> s >> t >> per;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (i == 1) {
      b[i] = max(s, a[i]);
    } else {
      b[i] = max(b[i - 1] + per, a[i]);
    }
  }
  if (n == 0 || a[1] > s) {
    cout << s << endl;
    return 0;
  }
  b[n + 1] = t;
  for (int i = 1; i <= n; i++) {
    if (b[i] + per * 2 <= t && b[i] + per < b[i + 1]) {
      cout << b[i] + per << endl;
      return 0;
    }
  }
  long long wait = 1e18, res;
  for (int i = 1; i <= n - 1; i++) {
    if (b[i] + per * 2 <= t && b[i] + per - (a[i + 1] - 1) < wait) {
      wait = b[i] + per - (a[i + 1] - 1);
      res = a[i + 1] - 1;
    }
  }
  if (a[1] > 0) {
    long long come = a[1] - 1;
    if (s - come < wait) wait = s - come, res = come;
  }
  cout << res << endl;
  return 0;
}
