const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;
void (async function () {
const seatNum = Number(await readline());
const seatOrLeave = (await readline()).split(" ").map(Number);
let seatIdx = [];
let lastSeatIdx = -1;
for (let info of seatOrLeave) {
if (info < 0) {
seatIdx = seatIdx.filter((idx) => idx !== -info);
continue;
}
if (seatIdx.length == seatNum) {
lastSeatIdx = -1;
continue;
}
if (seatIdx.length == 0) {
seatIdx.push(0);
lastSeatIdx = 0;
} else if (seatIdx.length == 1) {
seatIdx.push(seatNum - 1);
lastSeatIdx = seatNum - 1;
} else {
let bestSeatIdx = -1;
let bestSeatDis = -1;
let left = seatIdx[0];
for (let i = 1; i < seatIdx.length; i++) {
let right = seatIdx[i];
let dis = right - left - 1;
if (dis > 0) {
const curSeatDis = Math.floor(dis / 2) - (dis % 2 == 0 ? 1 : 0);
const curSeatIdx = left + curSeatDis + 1;
if (curSeatDis > bestSeatDis) {
bestSeatDis = curSeatDis;
bestSeatIdx = curSeatIdx;
}
}
left = right;
}
if (seatIdx[seatIdx.length - 1] !== seatNum - 1) {
const curSeatDis = seatNum - 1 - left;
const curSeatIdx = seatNum - 1;
if (curSeatDis > bestSeatDis) bestSeatIdx = curSeatIdx;
}
if (bestSeatIdx > 0) {
seatIdx.push(bestSeatIdx);
seatIdx.sort((a, b) => a - b);
}
lastSeatIdx = bestSeatIdx;
}
}
console.log(lastSeatIdx);
})();