import java.io.*; import java.util.*; public class Main { static final int[] WEIGHTS = 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[] p = sc.next().toCharArray(); char[] num = sc.next().toCharArray(); int count; if (num.length < 3) { count = Math.min(7, Integer.parseInt(new String(num))); } else { count = 7; } if (count == 0) { System.out.println(p); return; } int ans = 0; for (char c : p) { if (c == '-') { ans++; } else { ans += WEIGHTS[c - '0']; } } for (int i = 0; i < count - 1; i++) { ans = getAns(ans); } System.out.println(ans); } static int getAns(int x) { int ans = 0; while (x > 0) { ans += WEIGHTS[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 double nextDouble() throws Exception { return Double.parseDouble(next()); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }