/*
  AOJ 2157
  Title:
  @kankichi573
*/
#include <stdio.h>
#include <string.h>
int n;
char init[10],unlock[10],diff[10];
char find_zero(char *flag,char st,char end)
{
  char i;
  for(i=st;i<=end;i++)
    if(flag[i]==0)
      return(i);
  return(-1);
}
void dump_flag(char *flag)
{
  int i;
  for(i=0;i<10;i++)
    printf("%d:",flag[i]);
  printf("\n");
}
void dump_diff(char * diff,char * cnt,char * flag,int start,int end)
{
  int i;
  for(i=start;i<=end;i++)
    printf("%d:",diff[i]);
  printf("\n");
  for(i=0;i<10;i++)
    printf("%d:",cnt[i]);
 printf("\n");
 dump_flag(flag);
}
int rotate(char *diff,char start,char end)
{
  char cnt[10],flag[10],st,nn,fnd_start,fnd_end;
  int  i,max_,max_n,count;
  
  if(start==end)
    return(1);

  memset(cnt ,0,10);
  memset(flag,0,10);

  for(i=start;i<=end;i++)     //make histgram
    cnt[diff[i]]++;

  max_=0;                         //calc max 
  for(i=0;i<=9;i++)
    if(max_ < cnt[i])
	{
	  max_  = cnt[i];
	  max_n = i;
	}

  for(i=start;i<=end;i++)         //mark max digits  
    if(diff[i]==max_n)
      flag[i]=1;

  //dump_diff(diff,cnt,flag,start,end);

  // call myself (span which is flag off)
  count=1;
  if(start!=end)
    {
      fnd_start=start;
      fnd_end  =end; 

	while((st=find_zero(flag,fnd_start,end))!=-1)
	  {
	    for(i=st,nn=0;flag[i]==0 && i <=end ;i++)
	      nn++;
	    //printf("st=%d en=%d\n",st,st+nn-1);
	    count += rotate(diff,st,st+nn-1);
	    //dump_flag(flag);
	    fnd_start=i+1;
	  }
    }
  return(count);
}
int check_matched(char * diff,int n)
{
  int i;

  for(i=0;i<n;i++)
    if(diff[i])
      return(0);
  return(-1);
}

main()
{
  int i,max_,max_n;
  char d,count,st,nn;
  while(scanf("%d",&n) && n)
    {

      memset(diff,0,10);
      scanf("%s %s",init,unlock);

      for(i=0;i<n;i++)
	{
	  d = unlock[i]-init[i];
	  if(d<0)
	     d+=10;
	  diff[i]=d;
	}
      if(check_matched(diff,n))
            printf("%d\n",count);
      else
	{
	  count=rotate(diff,0,n-1);
	  printf("%d\n",count);
	}
      
    }
  return(0);
}