local DBG = false
function dbgpr(...)
    if DBG then
        io.write("[dbg]")
        print(...)
    end
end
function dbgpr_t(tbl)
    if DBG then
        for i,v in ipairs(tbl) do
            io.write("[dbg]")
            print(i,v)
        end
    end
end
function parse_table(N)
    local tbl = {}
    for i=1,N do
        table.insert(tbl, io.read("n"))
    end
    return tbl
end
function getline()
    local k = io.read("n")
    local tbl = parse_table(k)
    io.read("l")
    return tbl
end

function main()
    local n, m = io.read("n","n")
    io.read("l")
    local voted = {}
    for i=1,m do
        voted[i] = 0
    end
    for i=1,n do
        local like = getline()
        --dbgpr("like",i)
        --dbgpr_t(like)
        for i,v in ipairs(like) do
            voted[v] = voted[v] + 1
        end
    end
    local count = 0
    for i=1,m do
        if voted[i] == n then
            count = count + 1
        end
    end
    print(count)
end
main()
