#include <bits/stdc++.h>
const long long Inf = 2 * 1e15;
const long long mod = 1e9 + 7;
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  long long st, nd, t;
  cin >> st >> nd >> t;
  int n;
  cin >> n;
  long long mn = Inf, ans = 0;
  for (int(i) = 0; (i) < n; (i)++) {
    long long q;
    cin >> q;
    long long tt = q - 1;
    if (tt >= st) {
      cout << st;
      return 0;
    } else {
      long long tmp = st - tt;
      if (st + t <= nd && tmp < mn) {
        ans = tt;
        mn = tmp;
      }
    }
    st += t;
    if (st + t > nd) break;
  }
  if (st + t <= nd) {
    ans = st;
  }
  cout << ans;
  return 0;
}
