#include <stdio.h>

int main(void)
{
	int field[20][20], dis[20][20];
	int i, j;
	int x, y;
	int ans;
	
	while (1){
		
		scanf("%d %d", &x, &y);
		
		if (x == 0 && y == 0) break;
		
		for (i = 0; i < y; i++){
			for (j = 0; j < x; j++){
				scanf("%d", &field[i][j]);
				dis[i][j] = 0;
			}
		}
		
		for (i = 0; i < x; i++){
			if (field[0][i] == 0) dis[0][i] = 1;
		}
		for (i = 0; i < x; i++) dis[y][i] = 0;
		
		for (i = 0; i < y - 1; i++){
			for (j = 0; j < x; j++){
				
				if (field[i][j] == 2 && field[i + 2][j] != 1){
					dis[i + 2][j] = dis[i][j];
				}
				else{
					if (field[i + 1][j] != 1){
						dis[i + 1][j] += dis[i][j];
					}
					if (j != x - 1 && field[i + 1][j + 1] == 0){
						dis[i + 1][ j + 1] += dis[i][j];
					}
					if (j != 0 && field[i + 1][j - 1] == 0){
						dis[i + 1][ j - 1] += dis[i][j];
					}
				}
			}
		}
		ans = 0;
		
		for (i = 0; i < x; i++){
			ans += dis[y - 1][i];
			ans += dis[y][i];
		}
		
		printf("%d\n", ans);
	}
	return (0);
}