[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reads f = stdin.ReadLine().Split() |> Array.map f

let solve xs xss =
    let rec aux s = function
        | [] -> s
        | xs :: xss -> aux (Set.intersect s (Set.ofArray (Array.tail xs))) xss
    aux (Set.ofArray (Array.tail xs)) xss
    |> Set.toList
    |> List.length

[<EntryPoint>]
let main argv =
    let [|n;_|] = reads int
    let rs :: rss = List.map (fun _ -> reads int) [1..n]
    solve rs rss
    |> printfn "%i"
    0