// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

const int MAXN = 25;
vector< pair<int, int> > rows[MAXN], cols[MAXN];
int board[MAXN][MAXN], pos_r[MAXN], pos_c[MAXN], rec_r[MAXN], rec_c[MAXN];
int sx, sy, c;
map< pair<int, int>, int > mp;

int dfs(int bit, int k) {
    if(bit == 0) {
        return 1;
    }
    if(mp.count(make_pair(bit, k))) return mp[make_pair(bit, k)];
    
    int x = rec_r[k], y = rec_c[k];
    int xi = pos_r[k], xj = pos_c[k];

    int res = 0, b = __builtin_popcount(bit);
    for(int i=xi+1; i<(int)rows[x].size(); i++) {
        int id = rows[x][i].second;
        if(b > 1 and id == c-1) continue;
        if(bit >> id & 1) {
            int nbit = bit ^ (1 << id);
            res += dfs(nbit, id);
            break;
        }
    }
    for(int i=xi-1; i>=0; i--) {
        int id = rows[x][i].second;
        if(b > 1 and id == c-1) continue;
        if(bit >> id & 1) {
            int nbit = bit ^ (1 << id);
            res += dfs(nbit, id);
            break;
        }
    }
    for(int j=xj+1; j<(int)cols[y].size(); j++) {
        int id = cols[y][j].second;
        if(b > 1 and id == c-1) continue;
        if(bit >> id & 1) {
            int nbit = bit ^ (1 << id);
            res += dfs(nbit, id);
            break;
        }
    }
    for(int j=xj-1; j>=0; j--) {
        int id = cols[y][j].second;
        if(b > 1 and id == c-1) continue;
        if(bit >> id & 1) {
            int nbit = bit ^ (1 << id);
            res += dfs(nbit, id);
            break;
        }
    }
    return mp[make_pair(bit, k)] = res;
}

int solve_testcase() {
    int H, W; scanf("%d%d", &W, &H);
    if(H == 0 and W == 0) return 1;
    mp.clear();
    
    for(int i=0; i<MAXN; i++) {
        rows[i].clear();
        cols[i].clear();
    }

    c = 0;
    for(int i=0; i<H; i++) {
        for(int j=0; j<W; j++) {
            scanf("%d", &board[i][j]);
            if(board[i][j] == 1) {
                rows[i].emplace_back(j, c);
                cols[j].emplace_back(i, c);
                rec_r[c] = i;
                rec_c[c] = j;
                ++c;
            }
            if(board[i][j] == 2) {
                sx = i, sy = j;
            }
        }
    }

    {
        rows[sx].emplace_back(sy, c);
        cols[sy].emplace_back(sx, c);
        rec_r[c] = sx;
        rec_c[c] = sy;
        ++c;
    }
    
    for(int i=0; i<15; i++) {
        sort(rows[i].begin(), rows[i].end());
        sort(cols[i].begin(), cols[i].end());

        for(size_t k=0; k<rows[i].size(); k++) {
            int idx = rows[i][k].second;
            pos_r[idx] = k;
        }
        for(size_t k=0; k<cols[i].size(); k++) {
            int idx = cols[i][k].second;
            pos_c[idx] = k;
        }
    }
    
    int ans = dfs((1<<c)-1, c-1);
    printf("%d\n", ans);
    return 0;
}

int main() {
    while(!solve_testcase());
    return 0;
}



Measured memory_bytes: 73032