import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int current = sc.nextInt() % 10 * 100 + sc.nextInt() % 10 * 10 + sc.nextInt() % 10; long k = sc.nextLong(); int[] place = new int[1000]; int count = 0; int interval = 0; for (int i = 4; i <= 1004; i++) { if (i == k) { System.out.println((current / 100 + current % 100 / 10 + current % 10) % 10); return; } if (place[current] != 0) { count = place[current]; interval = i - place[current]; break; } place[current] = i; current = getNext(current); } long mod = (k - count) % interval; int ans = 0; for (int i = 0; i < 1000; i++) { if (count + mod == place[i]) { System.out.println((i / 100 + i % 100 / 10 + i % 10) % 10); return; } } } static int getNext(int x) { int count = x / 100 + x % 100 / 10 + x % 10; count %= 10; return (x * 10 + count) % 1000; } } 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(); } }