#include <cstdio>
#include <cstring>
int x, y;
int dp[15][15];
int mp[15][15];
int main() {
  while (scanf("%d%d",&x,&y)) {
    if (!x&&!y) break;
    memset(dp, 0, sizeof(dp));
    memset(mp, 0, sizeof(mp));
    for (int i=0; i<y; i++) {
      for (int j=0; j<x; j++) scanf("%d",&mp[i][j]);
    }
    for (int i=0; i<x; i++) if (mp[0][i]!=1) dp[0][i]=1;
    int res = 0;
    for (int i=0; i<y-1; i++) {
      for (int j=0; j<x; j++) {
        if (mp[i][j]==1) continue;
        if (mp[i][j]==2) {
          if (i+2>=y) res+=dp[i][j];
          else dp[i+2][j]+=dp[i][j];
        } else {
          if (j!=0&&mp[i+1][j-1]==0) dp[i+1][j-1]+=dp[i][j];
          if (mp[i+1][j]!=1) dp[i+1][j]+=dp[i][j];
          if (j!=x-1&&mp[i+1][j+1]==0) dp[i+1][j+1]+=dp[i][j];
        }
      }
    }
    for (int i=0; i<x; i++) res+=dp[y-1][i];
    printf("%d\n",res);
  }
}