import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); long value = 0; for (char c : sc.next().toCharArray()) { if (c == '-') { value++; } else { value += function(c - '0'); } } String n = sc.next(); int time = 6; if (n.length() == 1 && Integer.parseInt(n) < 6) { time = Integer.parseInt(n); } for (int i = 1; i < time; i++) { value = function(value); } System.out.println(value); } static int[] CONST = new int[]{6, 2, 5, 5, 4, 5, 6, 4, 7, 6}; static int function(long x) { if (x < 10) { return CONST[(int)x]; } int ans = 0; if (x > 0) { ans += CONST[(int)(x % 10)]; x /= 10; } return ans; } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }