require 'set'
n = gets.to_i
left_nodes = Set[0]
right_nodes = Set.new
g = {?s => Set[0], 0 => Set.new}

def augument_path(g, s = ?s, reached = Set[?s])
    return [[?t], reached] if s == ?t
    g[s].each do |v|
        next if reached.include?(v)
        path, reached = augument_path(g, v, reached + [v])
        if path
            return [[s] + path, reached]
        end
    end
    return [nil, reached]
end

k = 0
(1..n).each do |j|
    i = gets.to_i
    if left_nodes.include?(i)
        right_nodes << j
        g[j] = Set[?t]
        g[i] << j
    else
        left_nodes << j
        g[?s] << j
        g[j] = Set[i]
    end
    path, _ = augument_path(g)
    if path
        k += 1
        path.each_cons(2) do |u, v|
            g[u].delete(v)
            (g[v] ||= Set.new) << u
        end
    end
    p k
end

