loop do
    w, h = gets.split.map(&:to_i)
    break if w == 0
    a = (1..h).map { gets.split.map(&:to_i) }
    a << Array.new(w, 0)
    t = (1..h+1).map { Array.new(w, 0) }
    (0..w-1).each do |j|
        t[0][j] = (a[0][j] == 0 ? 1 : 0)
    end
    (0..h-1).each do |i|
        (0..w-1).each do |j|
            # next if t[i][j] == 0
            if i == h - 1
                t[i+1][j] += t[i][j]
            elsif a[i][j] == 2
                t[i+2][j] += t[i][j] if a[i+2][j] != 1
            else
                t[i+1][j-1] += t[i][j] if j > 0 && a[i+1][j-1] == 0
                t[i+1][j+1] += t[i][j] if j < w-1 && a[i+1][j+1] == 0
                t[i+1][j] += t[i][j] if a[i+1][j] != 1
            end
        end
    end
    puts t[-1].inject(:+)
end

