package yukicoder; import java.util.Scanner; public class No1458 { public static void main(String[] args) { Scanner scan = new Scanner(System.in); String P = scan.next(); String N = scan.next(); scan.close(); int[] T = new int[] {6, 2, 5, 5, 4, 5, 6, 4, 7, 6}; int n = N.length() > 1 ? 10 : Integer.valueOf(N); if (n == 0) { System.out.println(P); return; } int p = 0, i = 0; if (P.charAt(0) == '-') { p++; i++; } for (; i < P.length(); i++) { p += T[P.charAt(i) - '0']; } for (i=0; i < n-1; i++) { if (p == 4 || p == 5 || p == 6) { break; } int np = 0; while (p > 0) { np += T[p % 10]; p /= 10; } p = np; } System.out.println(p); } }