N=gets.chomp.to_i
array=gets.chomp.split(" ").map(&:to_i)
ret=0
stock={}
stock[array[0]] ||= 0
stock[array[1]] ||= 0
stock[array[0]]+=1
stock[array[1]]+=1
(N-1).times do |n|
    new1 = array[n*3+2]
    new2 = array[n*3+3]
    new3 = array[n*3+4]
    if new1==new2 && new2==new3
        ret+=1
        next
    end
    stock[new1] ||= 0
    stock[new2] ||= 0
    stock[new3] ||= 0
    stock[new1]+=1
    stock[new2]+=1
    stock[new3]+=1
    if new1 != new2 && new1 != new3 && new2 != new3
        if stock[new1] == 3
            stock={}
            stock[new2]=1
            stock[new3]=1
            ret+=1
        elsif stock[new2] == 3
            stock={}
            stock[new1]=1
            stock[new3]=1
            ret+=1
        elsif stock[new3] == 3
            stock={}
            stock[new1]=1
            stock[new2]=1
            ret+=1
        end
    else
        if stock[new1] >= 3
            stock[new1]-=3
            stock.keys.each do |key|
                next if key==new1 || key==new2 || key==new3
                stock[key] = 1 if stock[key] > 1
            end
            ret+=1
        elsif stock[new2] >= 3
            stock[new2]-=3
            stock.keys.each do |key|
                next if key==new1 || key==new2 || key==new3
                stock[key] = 1 if stock[key] > 1
            end
            ret+=1
        elsif stock[new3] >= 3
            stock[new3]-=3
            stock.keys.each do |key|
                next if key==new1 || key==new2 || key==new3
                stock[key] = 1 if stock[key] > 1
            end
            ret+=1
        end
    end
end
if stock[array[3*N-1]] == 2
    ret+=1
end
puts ret
