#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7, N = 100007;
int n;
long long ts, tf, t, a[N], ans = (long long)1e18, id;
int main() {
  cin >> ts >> tf >> t;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  while (a[n] > tf - t) n--;
  a[++n] = tf - t + 1;
  long long cur = 0;
  for (int i = 1; i <= n; i++) {
    cur = max(cur, ts);
    if (ans > cur - (a[i] - 1)) {
      ans = cur - (a[i] - 1);
      id = a[i] - 1;
    }
    if (cur < a[i]) {
      cout << cur;
      return 0;
    }
    cur = max(cur, a[i]);
    cur += t;
    if (cur >= tf - t + 1) break;
  }
  cout << id;
  return 0;
}
