module IntSet = Set.Make (struct
  type t = int
  let compare = compare
end)

let () = Scanf.scanf "%d %d\n" @@ fun n m ->
  let ass =
    Array.init n @@ fun _ ->
      Array.to_list @@ Array.init m @@ fun _ ->
        Scanf.scanf "%d " @@ fun a -> a - 1 in
  let rec solve s =
    if IntSet.is_empty s then max_int
    else begin
      let count = Array.make m 0 in
      Array.iter (fun as_ ->
        let a = List.find (fun a -> IntSet.mem a s) as_ in
        count.(a) <- 1 + count.(a)) ass;
      let n, a = IntSet.fold (fun a -> max (count.(a), a)) s (min_int, 0) in
      min n @@ solve @@ IntSet.remove a s
    end in
  Printf.printf "%d\n" @@
    solve @@
    IntSet.of_list @@
    Array.to_list @@
    Array.init m @@ fun i -> i
