let ans board w h =
  let valid_pos (x, y) =
    0 <= x && x <= h + 1 && 0 <= y && y <= w + 1
  in
  let q = Queue.create () in
  let visited = Array.make_matrix (h+2) (w+2) false in
  visited.(0).(0) <- true;
  Queue.push (0,0) q;
  let rec aux num =
    if Queue.is_empty q then
      num
    else
      let (x,y) = Queue.pop q in
      let num' =
        List.fold_left (fun pre (x', y') ->
          if valid_pos (x', y') then
            if board.(x').(y') = 1 then  
              pre + 1
            else
              (if not visited.(x').(y') then
                (visited.(x').(y') <- true;
                Queue.push (x', y') q);
              pre)
          else
            pre 
        ) num (if x mod 2 = 0 then
                [(x-1,y-1); (x-1,y); (x+1,y-1); (x,y+1); (x+1,y); (x,y-1)]
               else
                [(x-1,y); (x,y-1); (x,y+1); (x+1,y+1); (x+1,y); (x-1,y+1)]
            )
      in
      aux num'
  in
  aux 0
;;

let (w,h) = Scanf.sscanf (read_line ()) "%d %d" (fun w h -> (w, h))
;;
let board = Array.make_matrix (h+2) (w+2) 0
;;

let rec parse i () =
  if i <= h then
    let inp = read_line () in
    let j = ref 1 in
    String.iter (fun c ->
       if c <> ' ' then
         (board.(i).(!j) <- int_of_char c - 48;
         j := !j + 1)
    ) inp;
    parse (i+1) ()
;;

parse 1 ();;

print_string (string_of_int (ans board w h));;

