#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <cstring>
#include <fstream>
#include <numeric>
#include <algorithm>

using namespace std;

int main(int argc, char **argv) {
  int x, y, field[15 * 15], route[15 * 15], rsum;

  while (true) {
    cin >> x >> y;
    if (x == 0 && y == 0)
      break;
    rsum = 0;
    memset(route, 0, sizeof(int) * x * y);
    for (int i = 0; i < y; i++)
      for (int j = 0; j < x; j++)
        cin >> field[i * y + j];
    for (int i = 0; i < x; i++) {
      int f = field[i];
      if (!f)
        route[i] = 1;
    }

    for (int i = 1; i < y; i++)
      for (int j = 0; j < x; j++) {
        int f = field[i * y + j];
        if (f == 0) {
          for (int k = -1; k <= 1; k++)
            if ((j + k >= 0 && j + k < x) &&
                ((k == 0 && field[(i-1) * y + j+k] == 2) ||
                 (field[(i-1) * y + j+k] != 2)))
              route[i * y + j] += route[(i-1) * y + j+k];
        } else if (f == 1) {
          route[i * y + j] = 0;
        } else if (f == 2 && i + 2 < y && field[(i+2) * y + j] != 1) {
          route[(i+2) * y + j] = route[(i-1) * y + j];
        } else if (f == 2) {
          rsum += route[(i-1) * y + j];
        }
      }
    for (int i = 0; i < x; i++)
      rsum += route[(y-1) * y + i];

    cout << rsum << endl;
    /* FOR DEBUG                                                                                                                                                                                            
    for (int i = 0; i < y; i++) {                                                                                                                                                                           
      for (int j = 0; j < x; j++) {                                                                                                                                                                         
        cout << route[i * y + j];                                                                                                                                                                           
        cout << ' ';                                                                                                                                                                                        
      }                                                                                                                                                                                                     
      cout << endl;                                                                                                                                                                                         
      }*/
  }
  return 0;
}