#include <bits/stdc++.h>
using namespace std;
long long ta, tb, t, n, a, m = 1e12 + 7, ans;
long long aabs(long long x) { return x > 0 ? x : -x; }
int main() {
  cin >> ta >> tb >> t >> n;
  while (n--) {
    cin >> a;
    if (a && a <= tb - t) {
      if (max(ta, a - 1) <= tb - t && aabs(ta - a + 1) < m)
        m = aabs(ta - a + 1), ans = min(a - 1, ta);
      ta = max(ta, a) + t;
    }
  }
  if (ta <= tb - t) ans = ta;
  cout << ans << endl;
  return 0;
}
