def f(x) if x<0 1+f(-x) else ret=0 x.to_s.bytes{|c| ret+=[6,2,5,5,4,5,6,4,7,6][c-48] } ret end end x,n=gets.split.map &:to_i while n>0 n-=1 y=f(x) if x==y break end x=y end p x