#include<cstdio>
#include<map>
using namespace std;int x[144],m,n,w,ch;int z[]={-12,-1,1,12};map<int,int>y;int func(int p,int d,int u){while(1){int h=x[p];if(h>=0){int s=0;x[p]=-1;w^=1<<h;if(u>12){for(int i=0;i<4;i++)s+=func(p+z[i],z[i],u-1);}else{int mi=h<<23|w;map<int,int>::iterator it=y.find(mi);if(it==y.end()){for(int i=0;i<4;i++)s+=func(p+z[i],z[i],u-1);y[mi]=s;}else{s=it->second;}}w|=1<<h;x[p]=h;return s;}if(h==-9)break;p+=d;}return 0;}int main(){int i,j,p,t;for(;scanf("%d%d",&m,&n),m;y.clear()){w=0;for(i=0;i<144;i++)x[i]=-9;for(i=1;i<=n;i++)for(j=1;j<=m;j++){p=i*12+j;scanf("%d",&t);switch(t){case 2:ch=p;case 0:x[p]=-1;break;case 1:y[w<<23]=0;x[p]=w++;break;}}for(i=0;i<4;){t=z[i++];for(j=ch;x[j+=t]!=-9;x[j]>=0?y[x[j]<<23]=1:0);}j=w;w=(1<<w)-1;t=0;for(i=-1;++i<4;)t+=func(ch+z[i],z[i],j);printf("%d\n",t);}}