#include<iostream>
#include<map>
#include<algorithm>
using namespace std;
typedef pair<int,int> P;
int bfs(P sg,int home);
int w,h;
int mas[10][10];
int dx[]={0,1,0,-1},dy[]={-1,0,1,0};
P sg;

int main(){
	while(1){
		cin >> w >> h;
		if(w == 0 && h == 0) break;
		int home = 0;
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				cin >> mas[i][j];
				if(mas[i][j] == 1) home++;
				else if (mas[i][j] == 2) sg = P(j,i);
			}
		}
		cout << bfs(sg,home) << endl;
	}
}

int bfs(P now,int home){
	if(home == 0){
		if(now.first == sg.first || now.second == sg.second) return 1;
		else return 0;
	}
	int ret = 0;
	for(int i=0;i<4;i++){
		P p = now;
		while(1){
			p.first += dx[i]; p.second += dy[i];
			if(p.first >= 0 && p.second >= 0 && p.first < w && p.second < h){
				if(mas[p.second][p.first] == 1) break;
			}else{
				p = P(-1,-1); break;
			}
		}
		if(p.first == -1) continue;
		mas[p.second][p.first] = -1;
		ret += bfs(p,home-1);
		mas[p.second][p.first] = 1;
	}
	return ret;
}