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

int h, w;
int m[16][16];

int n;
int sy, sx;

int dfs(int y, int x, int b = (1 << n) - 1)
{
  if (b == 0){
    return (y == sy || x == sx);
  }

  int ret = 0;
  for (int i = y - 1; i >= 0; i--){
    if (m[i][x] == -1) continue;
    if (b & (1 << m[i][x])){
      ret += dfs(i, x, b - (1 << m[i][x]));
      break;
    }
  }
  for (int i = y + 1; i < h; i++){
    if (m[i][x] == -1) continue;
    if (b & (1 << m[i][x])){
      ret += dfs(i, x, b - (1 << m[i][x]));
      break;
    }
  }
  for (int i = x - 1; i >= 0; i--){
    if (m[y][i] == -1) continue;
    if (b & (1 << m[y][i])){
      ret += dfs(y, i, b - (1 << m[y][i]));
      break;
    }
  }
  for (int i = x + 1; i < w; i++){
    if (m[y][i] == -1) continue;
    if (b & (1 << m[y][i])){
      ret += dfs(y, i, b - (1 << m[y][i]));
      break;
    }
  }

  return ret;
}

int main()
{
  while (cin >> w >> h, w){
    n = 0;
    for (int i = 0; i < h; i++){
      for (int j = 0; j < w; j++){
        cin >> m[i][j];
        if (m[i][j] == 0) m[i][j] = -1;
        if (m[i][j] == 2) {
          sy = i; sx = j;
          m[i][j] = -1;
        }
        if (m[i][j] == 1) m[i][j] = n++;
      }
    }

    cout << dfs(sy, sx) << endl;
  }
}