function solution(n,m)
len=string.len(m)
num1={}
num2={}
num3={}
for i=0,len-1,1 do
if m%10~=0 then
num1[len-i-1]=m%10endif m%10==0 then
num1[len-i-1]=0endm=m//10endlocal step=1for i=1,30,1 do
for i=0,len-1,1 do
num2[len-1-i]=num1[i]
endfor i=0,len,1 do
num3[i]=0endfor i=0,len-1,1 do
num3[len-1-i]=num3[len-1-i]+num1[i]+num2[i]
endfor i=0,len-1,1 do
if num3[i]>=n then
num3[i]=num3[i]-n
num3[i+1]=num3[i+1]+1endendif num3[len]~=0 then
len=len+1endflag=0for i=0,len//2+1,1 do
if num3[i]~=num3[len-1-i] then
flag=1endendif flag==0 then
print("STEP:")
print(step)
breakendfor i=0,len-1,1 do
num1[i]=num3[len-1-i]
endstep=step+1if step==31 then
print("impossible")
endendendn=io.read("*n")
m=io.read("*n")
solution(n,m)