#include <iostream>
#define MAX 15

using namespace std;

int a,b,cnt,ans;
int ski[MAX][MAX];

int compute(int y,int x){

  if( ski[y][x] == 1 ) return cnt;
  if( b - 1 <= y ) return ++cnt;

  if( ski[y][x] == 2 ) compute( y + 2 , x );

  if( ski[y][x] != 2 ){
    if( ski[y + 1][x] == 2 ) compute( y + 3 , x );  
    if( !ski[y + 1][x - 1] && ( 0 <= x - 1 && x - 1 < a ) ) compute( y + 1 , x - 1 );
    if( !ski[y + 1][x + 1] && ( 0 <= x + 1 && x + 1 < a ) ) compute( y + 1 , x + 1 );
    if( !ski[y + 1][x] ) compute( y + 1 , x );
  }

  
  return cnt;
}



int main(void){

  while( cin >> a >> b , a || b ){

    for( int i = 0 ; i < b ; i++ )
      for( int j = 0 ; j < a ; j++ )
	cin >> ski[i][j];

    ans = 0;
    for( int i = 0 ; i < a ; i++ ){
      if( ski[0][i] == 0 ){
	cnt = 0;
	int c = compute( 0 , i );
	// cout << ski[0][i] << endl;
	ans += c;
      }
    }
    cout << ans << endl;


  }
  return 0;
}