n = io.read("*n") t = {} for i = 1, n do t[i] = io.read("*n") end tgt = n for i = n, 1, -1 do if(t[i] == tgt) then tgt = tgt - 1 end end print(tgt)