import java.io.*; import java.util.*; import java.util.function.*; import java.util.stream.*; public class Main { static int[] exchange = new int[]{6, 2, 5, 5, 4, 5, 6, 4, 7, 6}; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); char[] inputs = sc.next().toCharArray(); String n = sc.next(); if (n.length() <= 2) { int count = Integer.parseInt(n); if (count == 0) { System.out.println(inputs); } else { int current = func(inputs); for (int i = 1; i < count; i++) { current = func(String.valueOf(current).toCharArray()); } System.out.println(current); } } else { int current = func(inputs); while (current != 4 && current != 6) { current = func(String.valueOf(current).toCharArray()); } System.out.println(current); } } static int func(char[] arr) { int ans = 0; for (char c : arr) { if (c == '-') { ans++; } else { ans += exchange[c - '0']; } } return ans; } } class Scanner { BufferedReader br; StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() { try { br = new BufferedReader(new InputStreamReader(System.in)); } catch (Exception e) { } } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String next() { try { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } } catch (Exception e) { e.printStackTrace(); } finally { return st.nextToken(); } } }