#include <math.h>
#include <utility>
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

int main(){
	while(true) {
		int x;
		int y;
		cin >> x >> y;
		if ( x == 0 ) break;
		int a[15][15] = {0};
		for ( int i = 0; i < y ; i++ ) {
			for ( int j = 0; j < x ; j++ ) {
				cin >> a[j][i];
			}
		}
		int b[15][15] = {0};
		for ( int j = 0; j < x ; j++ ) {
			b[j][y-1] = 1;
		}
		if ( y > 1 ) {
			for ( int j = 0; j < x ; j++ ) {
				if ( a[j][y-2] == 2) b[j][y-2] = 1;
			}
		}
		for ( int i = y - 1; i > 0; i-- ) {
			for ( int j = 0; j < x ; j++ ) {
				if ( a[j][i] == 0 ) {
					for ( int k = j - 1; k < j + 2; k++ ) {
						if ( k < 0 || k >= x ) continue;
						if ( a[k][i-1] == 0 ) {
							b[k][i-1] += b[j][i];
						}
					}
					if ( i > 1 ) {
						if ( a[j][i-2] == 2 ) b[j][i-2] += b[j][i];
					}
				}else if ( a[j][i] == 2 ) {
					if ( a[j][i-1] == 0 ) b[j][i-1] += b[j][i];
					if ( i > 1 ) {
						if ( a[j][i-2] == 2 ) b[j][i-2] += b[j][i];
					}
				}
			}
		}
		int s = 0;
		for ( int j = 0; j < x ; j++ ) {
			s += b[j][0];
		}
		cout << s << endl;
	}
	return 0;
}