#include <iostream>
#define MAX 15

using namespace std;

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

int compute(int y,int x){

  if( a - 1 <= y ) return ++cnt;

  if( ski[y][x] == 2 ) compute( y + 2 , x );
  else if( ski[y + 1][x] == 2 ) compute( y + 3 , x );
  if( ski[y][x] != 2 ){
    if( !ski[y + 1][x - 1] && ( 0 <= x - 1 && x - 1 < b ) ) compute( y + 1 , x - 1 );
    if( !ski[y + 1][x + 1] && ( 0 <= x + 1 && x + 1 < b ) ) 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 < a ; i++ )
      for( int j = 0 ; j < b ; j++ )
	cin >> ski[i][j];

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


  }
  return 0;
}