#include int ri() { int n; scanf("%d", &n); return n; } int main() { constexpr int data[] = {6, 2, 5, 5, 4, 5, 6, 4, 7, 6}; std::string s; std::cin >> s; int64_t n; std::cin >> n; if (n == 0) { std::cout << s << std::endl; return 0; } int cur = 0; if (s[0] == '-') cur++, s.erase(s.begin()); for (auto i : s) cur += data[i - '0']; auto apply = [&] (int x) { int res = 0; for (int t = x; t; t /= 10) res += data[t % 10]; return res; }; std::map res; res[cur] = 1; for (int i = 1; i < n; i++) { int next = apply(cur); if (res.count(next)) { int period = (i + 1 - res[next]); int left = (n - (i + 1)) % period; for (int j = 0; j < left; j++) cur = apply(cur); printf("%d\n", cur); return 0; } res[next] = i + 1; cur = next; } printf("%d\n", cur); return 0; }