#include <iostream>
#include <vector>

struct Skier {
	int naname{ 0 }, straight{ 1 }, fling{ 0 };
	int land() const { return naname + straight; }
};
class Field {
	enum class State : char {
		Plane, Tree, Jump
	};
public:
	Field(const int &ah, const int &aw) :h{ ah }, w{ aw }, map(ah, std::vector<State>(aw)) {
		int a;
		for (auto &line : map) {
			for (auto &cell : line) {
				std::cin >> a;
				switch (a) {
				case 0: cell = State::Plane; break;
				case 1: cell = State::Tree; break;
				case 2: cell = State::Jump; break;
				}
			}
		}
	}
	int cul_route() const;
private:
	std::vector<std::vector<State>> map;
	int h, w;
};
int Field::cul_route() const {
	std::vector<std::vector<Skier>> temp_route(h, std::vector<Skier>(w + 2));
	for (auto y = 0; y < temp_route.size() - 1; ++y) {
		for (auto x = 1; x <= w; ++x) {
			switch(map[y][x - 1]) {
			case State::Plane:
				temp_route[y + 1][x - 1].naname += temp_route[y][x].land();
				temp_route[y + 1][x + 1].naname += temp_route[y][x].land();
				temp_route[y + 1][x].straight = temp_route[y][x].land() + temp_route[y][x].fling;
				break;
			case State::Jump:
				temp_route[y + 1][x].fling = temp_route[y][x].straight;
			case State::Tree:
				temp_route[y + 1][x].straight = temp_route[y][x].fling;
			}
		}
	}
	int sum = 0;
	for (auto x = 1; x <= w; ++x) {
		switch (map[h - 1][x - 1]) {
		case State::Plane:
			sum += temp_route[h - 1][x].naname;
		case State::Jump:
			sum += temp_route[h - 1][x].straight;
		case  State::Tree:
			sum += temp_route[h - 1][x].fling;
		}
	}
	return sum;
}
int main() {
	int h, w;
	while (std::cin >> h >> w && h != 0 && w != 0) {
		Field field(h, w);
		std::cout << field.cul_route() << std::endl;
	}
	return 0;
}