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