#include <iostream>
#include <vector>

enum class State {
	Empty, Tree, Jump
};
class Ski_run {
public:
	Ski_run(const int &x, const int &y) :width(x), height(y), state(y, std::vector<State>(x, State::Empty)), route(y + 1, std::vector<long long int>(x, 0)), null(0), res(-1) {
		for (auto &line : state) {
			for (auto &c : line) {
				int a;
				std::cin >> a;
				c = static_cast<State>(a);
			}
		}
		state.push_back(std::vector<State>(width, State::Empty));
		state.push_back(std::vector<State>(width, State::Empty));
		route.at(height) = std::vector<long long int>(x, 1);
		route.at(height - 1) = std::vector<long long int>(x, 1);
	}
	void show() const {
		for (const auto &l : route) {
			for (const auto &c : l) {
				std::cout << c;
			}
			std::cout << '\n';
		}
	}
	long long int solve() {
		if (res >= 0) {
			return res;
		}
		else {
			for (auto y = height - 2; y >= 0; --y) {
				for (auto x = 0; x < width; ++x) {
					switch (state.at(y).at(x)) {
					case State::Empty:
						if (at(x - 1, y + 1) == State::Empty) {
							route.at(y).at(x) += route.at(y + 1).at(x - 1);
						}
						if (at(x + 1, y + 1) == State::Empty) {
							route.at(y).at(x) += route.at(y + 1).at(x + 1);
						}
						if (!(at(x, y + 1) == State::Tree)) { 
							route.at(y).at(x) += route.at(y + 1).at(x);
						}
						break;
					case State::Jump:
						if (!(at(x, y + 2) == State::Tree)) {
							route.at(y).at(x) += route.at(y + 2).at(x);
						}
					}
				}
			}
			res = 0;
			for (const auto &l : route.at(0)) {
				res += l;
			}
			return res;
		}
	}
private:
	State at(const int &x, const int &y) {
		if (x >= 0 && width > x) {
			return state.at(y).at(x);
		}
		else {
			return State::Tree;
		}
	}
	int width, height;
	std::vector<std::vector<long long int>> route;
	std::vector<std::vector<State>> state;
	int null, res;
};
int main() {
	int x, y;
	std::cin >> x >> y;
	while (x != 0 || y != 0) {
		Ski_run state(x, y);
		std::cout << state.solve() << std::endl;
		std::cin >> x >> y;
	}
	return 0;
}