{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE UnboxedTuples #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE MultiWayIf #-}

import Control.Monad
import Control.Monad.ST
import Control.Monad.State
import Control.Monad.Primitive
import Control.Applicative
import Control.Arrow
import Data.List
import Data.Array
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
import Data.Maybe
import Data.Bits
import Data.Ord
import Data.Ratio
import Data.Int
import Data.Char
import qualified Data.IntMap as IM
import qualified Data.ByteString.Char8 as BS
import qualified Data.Set as Set
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.Vector.Generic as VG
import qualified Data.Vector.Generic.Mutable as VGM
import qualified Data.Sequence as Sq
import Data.Tuple
import Data.Function
import Text.Printf
import Debug.Trace
import Numeric

modifyArray arr i f = readArray arr i >>= \x -> writeArray arr i (f x)

listToTuple2 [a,b] = (a,b)
listToTuple3 [a,b,c] = (a,b,c)
listToTuple4 [a,b,c,d] = (a,b,c,d)
listToTuple5 [a,b,c,d,e] = (a,b,c,d,e)

readIntBS = fst . fromJust . BS.readInt

for = flip map

infixr 1 ?
(?) :: Bool -> (a,a) -> a
(?) b t = (if b then fst else snd) t

main :: IO ()
main = do
  [h,w] <- map read . words <$> getLine :: IO [Int]
  field <- map (map readIntBS . BS.words) . BS.lines <$> BS.getContents :: IO [[Int]]

  check <- newArray ((1,1),(w,h)) False :: IO (IOUArray (Int,Int) Bool)

  f <- newArray ((1,1),(w,h)) 0 :: IO (IOUArray (Int,Int) Int)

  forM_ (zip [1..h] field) $ \(y,l) -> do
    forM_ (zip [1..w] l) $ \(x,c) -> do
      writeArray f (x,y) c
  

  let
    solve :: StateT (Sq.Seq (Int,Int)) IO [(Int,Int,Int,Int)]
    solve = do
      queue <- get
      let ((x,y) Sq.:< rest) = Sq.viewl queue
      put rest

      s <- lift $ readArray f (x,y)
      if x == w && y == h then do
        return []
        
        else if x == w then do
        (lift $ readArray check (x,y+1)) >>= \checked -> unless checked $ ((modify $ (Sq.|> (x,y+1))) >> (lift $ writeArray check (x,y+1) True))

        if odd s then do
          lift $ modifyArray f (x,y) (+(-1))
          lift $ modifyArray f (x,y+1) (+1)
          ((y,x,y+1,x):) <$> solve
          else solve

        else if y == h then do
        (lift $ readArray check (x+1,y)) >>= \checked -> unless checked $ ((modify $ (Sq.|> (x+1,y))) >> (lift $ writeArray check (x+1,y) True))

        if odd s then do
          lift $ modifyArray f (x,y) (+(-1))
          lift $ modifyArray f (x+1,y) (+1)
          ((y,x,y,x+1):) <$> solve
          else solve

        else do
        (lift $ readArray check (x+1,y)) >>= \checked -> unless checked $ ((modify $ (Sq.|> (x+1,y))) >> (lift $ writeArray check (x+1,y) True))
        (lift $ readArray check (x,y+1)) >>= \checked -> unless checked $ ((modify $ (Sq.|> (x,y+1))) >> (lift $ writeArray check (x,y+1) True))

        if odd s then do
          lift $ modifyArray f (x,y) (+(-1))
          lift $ modifyArray f (x+1,y) (+1)
          ((y,x,y,x+1):) <$> solve
          else
          solve

  ans <- evalStateT solve (Sq.singleton (1,1))

  print $ length ans
  forM_ ans $ \(a,b,c,d) -> do
    printf "%d %d %d %d\n" a b c d
                          


Measured memory_bytes: 29308