let rec make_xy ?(l = [0]) n =
  match n with
  | 0 -> l
  | _ -> make_xy ~l:((List.hd l + read_int ()) :: l) (pred n)

let rec t2 t y l =
  match l with
  | [] -> t
  | h :: l' ->
    let n = Array.get t (y-h) in
    Array.set t (y-h) (succ n);
    t2 t y l'

let rec t1 t l =
  match l with
  | [] -> t
  | h :: l' -> t1 (t2 t h l') l'

let rec u2 t y l cnt =
  match l with
  | [] -> cnt
  | h :: l' ->
    let n = Array.get t (y-h) in
    u2 t y l' (cnt+n)

let rec u1 t l cnt =
  match l with
  | [] -> cnt
  | h :: l' -> u1 t l' (u2 t h l' cnt)

let rec solve () =
  match (read_int (), read_int ()) with
  | (0, 0) -> exit 0
  | (n, m) ->
    let y = make_xy n in
    let x = make_xy m in
    let t = Array.make (m*1000) 0 in
    let tt = t1 t y in
    let cnt = u1 tt x 0 in
    print_int cnt; print_newline ();
    solve ()

let () = solve ()