#include<iostream>
using namespace std;
int h,w,t,ans,gx,gy,map[10][10],dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
void DFS(int x,int y,int len){for(int i=0;i<4;i++){int xx=x+dx[i],yy=y+dy[i];while(true){if(xx>=0&&xx<w&&yy>=0&&yy<h){if(map[yy][xx]==1){map[yy][xx]=0;DFS(xx,yy,len+1);map[yy][xx]=1;break;}if(map[yy][xx]==2&&len==t){ans++;break;}}else break;xx+=dx[i],yy+=dy[i];}}}
int main(){while(true){cin>>w>>h;if(w==0&&h==0)break;t=0;for(int i=0;i<h;i++){for(int j=0;j<w;j++){cin>>map[i][j];if(map[i][j]==2)gy=i,gx=j;if(map[i][j]==1)t++;}}ans=0;DFS(gx,gy,0);cout<<ans<<endl;}return 0;}