#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int s, f, t, ans, counter, min = 1000000000001;
  cin >> s >> f >> t;
  int n;
  cin >> n;
  ans = s;
  counter = s;
  long long int num = 0;
  for (int i = 0; i < n; i++) {
    cin >> num;
    if (counter + t > f) {
      break;
    }
    if (num <= counter) {
      if (counter - num + 1 < min) {
        min = counter - num + 1;
        ans = num - 1;
      }
      counter += t;
    } else {
      cout << counter;
      exit(0);
    }
  }
  if (counter + t <= f) {
    cout << counter;
  } else {
    cout << ans;
  }
}
