/*
  AOJ 1504
  Title:Connect
  @kankichi573
*/
#include <stdio.h>

int r,c;
char ban[10][10];
void copy_ban(char to[10][10],char from[10][10])
{
  int i,j;
  for(i=0;i<r;i++)
    for(j=0;j<c;j++)
      to[i][j]=from[i][j];
}

int search_nz(char ban[10][10],int *y,int *x)
{
  int i,j;
  for(i=0;i<r;i++)
    for(j=0;j<c;j++)
      if(ban[i][j]>0)
	{
	  *y=i;*x=j;
	  return(0);
	}
  return(-1);
}
int search_nz_down(char ban[10][10],int y,int x,int *y1, int *x1)
{
  int i,j,cnt;
  for(i=y+1;i<r;i++)
    if((cnt=ban[i][x])<0)
      return(0);
    else if((cnt=ban[i][x])>0)
	{
	  *y1=i;*x1=x;
	  return(cnt);
	}
  return(0);
}
int search_nz_right(char ban[10][10],int y,int x,int *y1, int *x1)
{
  int i,cnt;
  for(i=x+1;i<c;i++)
    if((cnt=ban[y][i])<0)
      return(0);
    else if((cnt=ban[y][i])>0)
	{
	  *y1=y;*x1=i;
	  return(cnt);
	}
  return(0);
}
void dump(char ban[][10])
{
  int i,j;
  for(i=0;i<r;i++)
    {
      for(j=0;j<c;j++)
	if(ban[i][j]>0)
	  printf("%d",ban[i][j]);
	else if(ban[i][j]==-1)
	  printf("*",ban[i][j]);
	else
	  printf(".");
      printf("\n");
    }
  printf("---------\n");
}
void connect_line(char ban[10][10],int y,int x,int y1,int x1)
{
  int i;
  
  if(x==x1)
    for(i=y+1;i<y1;i++)
      ban[i][x]=-1;
  else if(y==y1)
    for(i=x+1;i<x1;i++)
      ban[y][i]=-1;
   
}

int solve(char ban[10][10])
{
  char my_ban[10][10];
  int x,y,i,sum,lines,ret=0,cnt_x,cnt_y;
  int x1,y1,x2,y2;

  //dump(ban);

  if(search_nz(ban,&y,&x)) //allzero
    return(1);

  cnt_x=search_nz_right(ban,y,x,&y1,&x1);
  cnt_y=search_nz_down (ban,y,x,&y2,&x2);

  //printf("xy=(%d %d)(%d %d)(%d %d)\n",y,x,y1,x1,y2,x2);
  //printf("cxy=%d %d",cnt_x,cnt_y);

  lines=ban[y][x];
  if(cnt_x+cnt_y < lines)
    return(0);

  if(lines==1)
    {
      if(cnt_x)
	{
	  copy_ban(my_ban,ban);
	  my_ban[y][x]=0;
	  my_ban[y1][x1]--;
	  connect_line(my_ban,y,x,y1,x1);
	  ret += solve(my_ban);
	}
     if(cnt_y)
	{
	  copy_ban(my_ban,ban);
	  my_ban[y][x]=0;
	  my_ban[y2][x2]--;
	  connect_line(my_ban,y,x,y2,x2);
	  ret += solve(my_ban);
	}	  
    }
  else if(lines==2)
    {
      if(cnt_x>1)
	{
	  copy_ban(my_ban,ban);
	  my_ban[y][x]=0;
	  my_ban[y1][x1]-=2;
	  connect_line(my_ban,y,x,y1,x1);
	  ret += solve(my_ban);
	}
     if(cnt_x>0 && cnt_y>0)
	{
	  copy_ban(my_ban,ban);
	  my_ban[y][x]=0;
	  my_ban[y1][x1]--;
	  my_ban[y2][x2]--;
	  connect_line(my_ban,y,x,y1,x1);
	  connect_line(my_ban,y,x,y2,x2);
	  ret += solve(my_ban);
	}
     if(cnt_y>1)
	{
	  copy_ban(my_ban,ban);
	  my_ban[y][x]=0;
	  my_ban[y2][x2]-=2;
	  connect_line(my_ban,y,x,y2,x2);
	  ret += solve(my_ban);
	}	  
    }
  else if(lines==3)
    {

     if(cnt_x>1 && cnt_y>0)
	{
	  copy_ban(my_ban,ban);
	  my_ban[y][x]=0;
	  my_ban[y1][x1]-=2;
	  my_ban[y2][x2]--;
	  connect_line(my_ban,y,x,y1,x1);
	  connect_line(my_ban,y,x,y2,x2);
	  ret += solve(my_ban);
	}
     if(cnt_x>0 && cnt_y>1)
	{
	  copy_ban(my_ban,ban);
	  my_ban[y][x]=0;
	  my_ban[y1][x1]--;
	  my_ban[y2][x2]-=2;
	  connect_line(my_ban,y,x,y1,x1);
	  connect_line(my_ban,y,x,y2,x2);
	  ret += solve(my_ban);
	}	  
    }
  else if(lines==4)
    {
     if(cnt_x>1 && cnt_y>1)
	{
	  copy_ban(my_ban,ban);
	  my_ban[y][x]=0;
	  my_ban[y1][x1]-=2;
	  my_ban[y2][x2]-=2;
	  connect_line(my_ban,y,x,y1,x1);
	  connect_line(my_ban,y,x,y2,x2);
	  ret += solve(my_ban);
	}
    }
  else
    ret=0;
  return(ret);
}
main()
{
  int i,j,ret;
  char x;

  scanf("%d %d ",&r,&c);
  for(i=0;i<r;i++)
    for(j=0;j<c;j++)
      {
	scanf("%c ",&x);
	if(x=='.')
	  ban[i][j]=0;
	else
	  ban[i][j]=x-'0';
      }
  ret=solve(ban);
  printf("%d\n",ret);
  return(0);
}