M = 17
m = Array.new(M).map{Array.new(M,0)}
memo = Array.new(M).map{Array.new(M,0)}
while true do
  x, y = gets.chomp.split().map(&:to_i)
  if x==0 && y==0 then
    break
  end
  for i in 0..y+1 do
    for j in 0..x+1 do
      m[i][j] = 1
      memo[i][j] = 0
    end
  end
  for i in 1..x do
    memo[1][i] = 1
  end
  for i in 1..y do
    m[i] = [1] + gets.chomp.split().map(&:to_i) + [1]
  end
  ans = 0
  for i in 2..y do
    for j in 1..x do
      if m[i][j]!=1 then
        if m[i][j]==0 then
          if m[i-1][j-1]!=2 then
            memo[i][j] += memo[i-1][j-1]
          end
          if m[i-1][j+1]!=2 then
            memo[i][j] += memo[i-1][j+1]
          end
        end
        if m[i-1][j]!=2 then
          memo[i][j] += memo[i-1][j]
        end
        if m[i-2][j]==2 then
          memo[i][j] += memo[i-2][j]
        end
      end
    end
  end
  for i in 1..x do
    ans += memo[y][i]
    if m[y-1][i]==2 then
      ans += memo[y-1][i]
    end
  end
  puts ans
end