let rec for_fold a b v f = if a >= b then v else for_fold (a+1) b (f v a) f

let rec print_trace = function
  | (a,b)::(c,d)::xs -> (
    Printf.printf "%d %d %d %d\n" (a+1) (b+1) (c+1) (d+1);
    print_trace ((c,d)::xs)
  )
  | _ -> ()

let () =
  Scanf.scanf "%d %d" @@ fun h w ->
  let a = Array.init h (fun _ -> Array.init w (fun _ -> Scanf.scanf " %d" ((+) 0))) in

  let moves, _ = for_fold 0 (h*w) ([], None) (fun (ac, tr) i ->
    let x = i / w in
    let y = if x mod 2 = 0 then i mod w else (w-1) - i mod w in
    match tr with
    | None ->
      if a.(x).(y) mod 2 = 1 then (ac, Some [(x, y)]) else (ac, None)
    | Some tr -> begin
      if a.(x).(y) mod 2 = 1 then (List.rev ((x,y)::tr) :: ac, None) else (ac, Some ((x,y)::tr))
    end)
  in

  let moves = List.rev moves in

  let n = List.fold_left (fun n x -> n + List.length x - 1) 0 moves in
  Printf.printf "%d\n" n;
  List.iter print_trace moves