Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
	)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for scanner.Scan() {
		buf := strings.Split(scanner.Text(), " ")
		X, _ := strconv.Atoi(buf[0])
		Y, _ := strconv.Atoi(buf[1])
		if X == 0 && Y == 0 {
			break
		}
		tbl := make([][]int, Y+2)
		field := make([][]int, Y+2)
		for i := range field {
			field[i] = make([]int, X+2)
			tbl[i] = make([]int, X+2)
			for j := range field[i] {
				field[i][j] = 2
				tbl[i][j] = 0
			}
		}
		buf_ := make([][]string, Y)
		for i := range buf_ {
			scanner.Scan()
			buf_[i] = strings.Split(scanner.Text(), " ")
		}
		for i := 1; i <= Y; i++ {
			for j := 1; j <= X; j++ {
				field[i][j], _ = strconv.Atoi(buf_[i-1][j-1])
				switch field[i][j] {
				case 0:
					if i == 1 {
						tbl[i][j] = 1 // スタートy=1
					} else {
						if field[i-1][j-1] != 2 {
							tbl[i][j] += tbl[i-1][j-1] // 左上からやってくる
						}
						if field[i-1][j] != 2 {
							tbl[i][j] += tbl[i-1][j] // 真上からやってくる
						}
						if field[i-1][j+1] != 2 {
							tbl[i][j] += tbl[i-1][j+1] // 右上からやってくる
						}
						if field[i-2][j] == 2 {
							tbl[i][j] += tbl[i-2][j] // ジャンプしてくる
						}
					}
				case 1:
					tbl[i][j] = 0 // 障害物あり
				case 2:
					if field[i-1][j] != 2 {
						tbl[i][j] += tbl[i-1][j] // 真上からくる
					}
					if field[i-2][j] == 2 {
						tbl[i][j] += tbl[i-2][j] // ジャンプ台からジャンプしてくる
					}
				}
			}
		}
		sum := 0
		for i := 1; i <= X; i++ {
			sum += tbl[Y][i] // とびこさないでゴール
			if field[Y-1][i] == 2 {
				sum += tbl[Y-1][i] // 飛び越してゴール
			}
		}
		fmt.Println(sum)
	}
}

C++: #include <iostream>
using namespace std;
int w,h;
int mp[20][20],memo[20][20];
int dx[] = {-1,0,1};

void saiki(int x,int y) {
  if(y >= h-1) memo[y][x]++;
  else if(mp[y][x] != 1) {
    for(int i=0;i<3;i++) {
      int nx = x+dx[i], ny = y+1;
      if(nx==x && mp[ny][nx] == 2)while(mp[ny][nx] == 2) ny+=2;

      if(nx <0|| nx >= w ||mp[ny][nx] == 1) continue;
      if(memo[ny][nx] > 0 && mp[ny][nx] == 0) memo[y][x] += memo[ny][nx];
      else if(mp[ny][nx] == 0){
	saiki(nx,ny);
	memo[y][x] += memo[ny][nx];
      }
    }
    if(memo[y][x] == 0) mp[y][x] = 1;
  }
}
  
int main() {
  while(1) {
    cin >> w >> h;
    if(w == 0 && h == 0) break;
    for(int i=0;i<=19;i++)
      for(int j=0;j<=19;j++)memo[i][j] = mp[i][j] = 0;
    
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++)cin >> mp[i][j];
 
    for(int i=0;i<w;i++) 
      if(mp[0][i] !=1) saiki(i,0);
    
    int cnt = 0;
    for(int i=0;i<w;i++)
      if(memo[0][i] > 0) cnt+=memo[0][i];
    cout <<cnt<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <cstring>
using namespace std;

int w,h;
int map[16][16];
int dp[16][16][4][2];

int rec(int x,int y,int state,bool str){
    if(state == 1 || x < 0 || x >= w) return 0;
    if(state == 2 && !str) return 0;
    if(y >= h-1) return 1;
    if(dp[y][x][state][str] != -1) return dp[y][x][state][str];
    int res;
    if(state == 2) res = rec(x,y+2,map[y+2][x],true);
    else res = (rec(x-1,y+1,map[y+1][x-1],false) + rec(x,y+1,map[y+1][x],true) + rec(x+1,y+1,map[y+1][x+1],false));
    return dp[y][x][state][str] = res;
}

int main(){
    while(cin >> w >> h,w||h){
        memset(dp,-1,sizeof(dp));
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++) cin >> map[i][j];
        }
        int d = 0;
        for(int i=0;i<w;i++) d += rec(i,0,map[0][i],true);
        cout << d << endl;
    }
}

C++: #include <bits/stdc++.h>

#define all(a)  (a).begin(),(a).end()
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define exist(s,e) ((s).find(e)!=(s).end())
#define pb push_back
#define range(i,a,b) for(int (i)=(a);(i)<(b);++(i))
#define rep(i,n)  range(i,0,n)
#define dump(x)  cerr << #x << " = " << (x) << endl;

using namespace std;

typedef vector<int> vi;
typedef long long ll;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int w,h;
int course[20][20];
ll dp[20][20];

int main(void){
	while(cin >> w >> h,w|h){
		clr(dp,0);
		rep(i,h)rep(j,w) cin >> course[i][j];
		rep(i,w) if(course[0][i]==0) dp[0][i]=1LL;
		rep(i,h-1)rep(j,w){
			if(course[i][j]==2&&course[i+2][j]!=1) dp[i+2][j]+=dp[i][j];
			if(course[i][j]) continue;
			for(int nj=j-1;nj<=j+1;++nj){
				if(nj<0||w<=nj) continue;
				if(course[i+1][nj]==1) continue;
				if(j!=nj&&course[i+1][nj]==2) continue;
				dp[i+1][nj]+=dp[i][j];
			}
		}
		/*
		rep(i,h+1){
			rep(j,w) cerr << dp[i][j] << " ";
			cerr << endl;
		}*/
		ll ans=0LL;
		range(i,h-1,h+1)rep(j,w) ans+=dp[i][j];
		cout << ans << endl;
	}
	return 0;
}

C++: /* {{{ Shinobu kawaii */
/*
  ______   __        _                  __                 
.' ____ \ [  |      (_)                [  |                
| (___ \_| | |--.   __   _ .--.   .--.  | |.--.   __   _   
 _.____`.  | .-. | [  | [ `.-. |/ .'`\ \| '/'`\ \[  | | |  
| \____) | | | | |  | |  | | | || \__. ||  \__/ | | \_/ |, 
 \______.'[___]|__][___][___||__]'.__.'[__;.__.'  '.__.'_/ 

*/
// clang-format off
/* }}} */

#include <bits/stdc++.h>
using namespace std;

// #define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* cpp template {{{ */

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T> inline void print(const T& x) {cout << x << '\n';}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {REP(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}
// clang-format on
/* }}} */

int w, h;
int field[20][20];
int memo[20][20];

ll dfs(int y, int x, int yy = -1, int xx = -1) {
  if (!inside(y, x, INF, w)) return 0;
  if (field[y][x] == 1) return 0;
  if (y > h - 1) return 1;
  if (y == h - 1 && field[y][x] == 0) return 1;
  if (field[y][x] == 2 && x != xx) return 0;

  if (memo[y][x] != -1) return memo[y][x];

  ll res;
  if (field[y][x] == 2) {
    res = dfs(y + 2, x, y, x);
  } else {
    res = dfs(y + 1, x, y, x) + dfs(y + 1, x + 1, y, x) + dfs(y + 1, x - 1, y, x);
  }

  return memo[y][x] = res;
}

signed main() {
  while (cin >> w >> h, w || h) {
    memset(field, -1, sizeof(field));
    memset(memo, -1, sizeof(memo));
    REP(i, h) REP(j, w) field[i][j] = in();
    ll ans = 0;
    REP(i, w) {
      ans += dfs(0, i);
    }
    print(ans);
  }

  return 0;
}