#include <bits/stdc++.h>
using namespace std;
long long v[100005];
int main() {
  long long ts, tf, t, ans = 0, dif = (1LL << 60), act;
  int n, i;
  cin >> ts >> tf >> t >> n;
  for (i = 1; i <= n; ++i) cin >> v[i];
  act = ts;
  for (i = 1; i <= n; ++i) {
    if (v[i] <= act) {
      if (act + t > tf) break;
      if (dif > act - v[i] + 1) {
        dif = act - v[i] + 1;
        ans = v[i] - 1;
      }
      act += t;
    } else {
      dif = 0;
      ans = v[i] - 1;
    }
  }
  if (act + t <= tf) ans = act;
  cout << ans;
  return 0;
}
